python

(Python) Closure created when it wasn't expected

I got an unexpected closure when creating a nested class. I suspect that this is something related to metaclasses, super, or both. It is definitely related to how closures get created. I am using python2.7. Here are five simplified examples that demonstrate the same problem that I am seeing (they all build off the first): EXAMPLE ...

Finding Regex Pattern after doing re.findall

Hi This is in continuation of my earlier question where I wanted to compile many patterns as one regular expression and after the discussion I did something like this REGEX_PATTERN = '|'.join(self.error_patterns.keys()) where self.error_patterns.keys() would be pattern like : error: : warning: cc1plus: undefine reference to Fa...

Graphing in Python 3.x

In Python 2.6, I used matplotlib to make some simple graphs. However, it is incompatible with Python 3.1. What are some alternative modules that can accomplish the same thing without being very complex? ...

python twisted tutorial/question

Hi guys... Got a simple question regarding twisted. I can create a trivial basic test with a web server like apache, where http://foo.com/index.php instantiates the index.php for the "foo" site/app... I'm trying to figure out how the heck I can create a twisted server, where I run different backend functions based on the input! I kno...

Why custom types accept ad-hoc attributes in Python (and built-ins don't)?

Hi there! I'd like to know why one is able to create a new attribute ("new" means "not previously defined in the class body") for an instance of a custom type, but is not able to do the same for a built-in type, like object itself. A code example: >>> class SomeClass(object): ... pass ... >>> sc = SomeClass() >>> sc.name = "AAA"...

Need to restart python in Terminal every time a change is made to script

Every time I make a change to a python script I have to reload python and re-import the module. Please advise how I can modify my scripts and run then without having to relaunch python in the terminal. Thanks. ...

drop-down menu in python for Symbian

Hi, I want to implement a drop-down menu in python for Symbian. How do I create the drop-down and How can I access the selection value? thanks ...

.py to .exe, three questions

I want to package a Python script so that it can run as a standalone program on Windows XP and later Windows versions. Now to do this I'm pretty sure I'll have to convert it to an .exe file. I know methods exist, what is the easiest/best method? Now this is where the question gets a little more advanced. I also have some modules the p...

How do I run a django TestCase manually / against other database?

I have some methods written into a django.test.TestCase object that I'd like to run from the manage.py shell on my real database. But when I try to instantiate the TestCase object to run the test method, I get this error: ValueError: no such test method in <class 'track.tests.MentionTests'>: runTest Is there a way to instantiate the...

making a class behave like a bunch of keyword arguments in python

So I have a class that will have a lot of attributes. Is there a way to make this class behave in a way that I can pass it as a **kwarg to a function? class Foo ( object ) : def __init__( self ) : self.a = 'a' self.b = 'b' foo = Foo() somefunc(**foo) I cannot find the right operator to overload. Thanks a lot! ...

The "right" way to add python scripting to a non-python application

I'm currently in the process of adding the ability for users to extend the functionality of my desktop application (C++) using plugins scripted in python. The naive method is easy enough. Embed the python static library and follow any number of the dozens of tutorials scattered around the web describing how to initialize and call python...

How do I track motion using OpenCV in Python?

I can get frames from my webcam using OpenCV in Python. The camshift example is close to what I want, but I don't want human intervention to define the object. I want to get the center point of the total pixels that have changed over the course of several frame, i.e. the center of the moving object. ...

With the Python Imaging Library (PIL), how does one compose an image with an alpha channel over another image?

I have two images, both with alpha channels. I want to put one image over the other, resulting in a new image with an alpha channel, just as would occur if they were rendered in layers. I would like to do this with the Python Imaging Library, but recommendations in other systems would be fantastic, even the raw math would be a boon; I ...

py2exe, problems

I'm attempting to convert a .py file to a .exe file. However, I get a weird output. Output: usage: module1 [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: module1 --help [cmd1 cmd2 ...] or: module1 --help-commands or: module1 cmd --help error: no commands supplied My code: from distutils.core import setup import...

question comparing multiprocessing vs twisted

Hi. Got a situation where I'm going to be parsing websites. each site has to have it's own "parser" and possibly it's own way of dealing with cookies/etc.. I'm trying to get in my head which would be a better choice. Choice I: I can create a multiprocessing function, where the (masterspawn) app gets an input url, and in turn it spans...

Logical task for Python proggramers. Make tuple of lists. from list.

Ok! So i need to make tuple of list with 2 items. For example if i have list range(10) I need to make tuple like this: [(0,1),(2,3),(4,5),(6,7),(8,9)] How can i implametnt that? ...

Writing binary data to stdout with IronPython

I have two Python scripts which I am running on Windows with IronPython 2.6 on .NET 2.0. One outputs binary data and the other processes the data. I was hoping to be able to stream data from the first to the second using pipes. The problem I encountered here is that, when run from the Windows command-line, sys.stdout uses CP437 character...

What is the search order for free variables in Python?

Specifically, how are free variables bound at definition for methods of a class? It is probably something like this: enclosing function (temporary) scope => generate closure global (permanent) scope => generate no closure (just look it up when the method body executes) raise UnboundLocalError() Here are two examples: globalname = 0...

How to give Tkinter file dialog focus

I'm using OS X. I'm double clicking my script to run it from Finder. This script imports and runs the function below. I'd like the script to present a Tkinter open file dialog and return a list of files selected. Here's what I have so far: def open_files(starting_dir): """Returns list of filenames+paths given starting dir""" ...

TypeError: writelines() argument must be a sequence of strings

I have a weird error when try to redirect a exception to STDERR. I have a script that is use to load several "plugins", working as main entry program. The plugins do stuff like connect to databases, parsing text data, connect to web services, etc... Is like this: try: Run plugins here... #All was ok! print "...