python

Django foreign key access in save() function

Here's my code: class Publisher(models.Model): name = models.CharField( max_length = 200, unique = True, ) url = models.URLField() def __unicode__(self): return self.name def save(self): pass class Item(models.Model): publisher = models.ForeignKey(Publisher) name =...

Play a Sound with Python

What's the easiest way to play a sound file (.wav) in Python? By easiest I mean both most platform independent and requiring the least dependencies. pygame is certainly an option, but it seems overkill for just sound. ...

Create plugins for python standalone executables

Hi, how to create a good plugin engine for standalone executables created with pyInstaller, py2exe or similar tools? I do not have experience with py2exe, but pyInstaller uses an import hook to import packages from it's compressed repository. Of course I am able to import dynamically another compressed repository created with pyInstall...

anonymous unbound functions in python

I would like to do something like the following: def add(a, b): #some code def subtract(a, b): #some code operations = [add, subtract] operations[0]( 5,3) operations[1](5,3) In python, is it possible to assign something like a function pointer? ...

XML instance generation from XML schema (xsd)

I was wondering if there's a way I can automate the generation of XML files from XSD schemas given that I have the data and the labels. I'd like to do this in python/java. It seems very possible, yet I can't find any library that allows me to do this. I'm looking for a fairly quick solution.. Any ideas? See also: how-to-generate-samp...

Why do new instances of a class share members with other instances?

class Ball: a = [] def __init__(self): pass def add(self,thing): self.a.append(thing) def size(self): print len(self.a) for i in range(3): foo = Ball() foo.add(1) foo.add(2) foo.size() I would expect a return of : 2 2 2 But I get : 2 4 6 Why is this? I've found that by doing a=[] in the init, I can ...

What application you recommend to start peeking to learn Python style?

Do you know any application, the more interesting/useful the better, to introduce a new person to Python language and the Python code style, but not necessarily to OO programing, so as to learn the subtleties and idioms of the language and surrounding community? I'm thinking along the lines of people that has worked with JavaScript, Jav...

help me translate Java code making use of bytes into jython code

how do I translate this code into jython? ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file + ".zip")); byte[] buf = new byte[1024]; int len; //Create a new Zip entry with the file's name. ZipEntry zipEntry = new ZipEntry(file.toString()); //Create a buffered input stream out of the file ...

Showing processing message in Python

I want to show the processing information or log in the original page when the submitted request is being served until it completes the execution. I thought it would be meaningful to the user to know what is happening behind the request. I don't find a clue to do so though, can you guys help me out as how people are doing like this one ...

How to force iPython to use an older version of Python ?

I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was a ipython2.4 packa...

Adding REST to Django -- Poll

I've got a Django application that works nicely. I'm adding REST services. I'm looking for some additional input on my REST strategy. Here are some examples of things I'm wringing my hands over. Right now, I'm using the Django-REST API with a pile of patches. I'm thinking of falling back to simply writing view functions in Djang...

Python data structures overhead/performance.

Is there any performance advantage to using lists over dictionaries over tuples in Python? If I'm optimising for speed, is there any reason to prefer one over another? ...

pygtk glade question: why isn't this simple script working?

I've been writing writing a small pygtk application using glade to put together the UIs. I've created several windows already that work, but for some reason this one isn't working. I get the following traceback: Traceback (most recent call last): File "test.py", line 7, in <module> class TestClass: File "test.py", line 10, in ...

What does functools.wraps do?

In a comment on the answer to another question, someone said they weren't sure what functools.wraps was doing. So I'm asking this question so that there will be a record of it on StackOverflow for future reference: what does functools.wraps do, exactly? ...

Why can't I inherit from dict AND Exception in Python ?

I got the following class : class ConstraintFailureSet(dict, Exception) : """ Container for constraint failures. It act as a constraint failure itself but can contain other constraint failures that can be accessed with a dict syntax. """ def __init__(self, **failures) : dict.__init__(self, failures) ...

Komodo Edit and Notepad++ ::: Pros & Cons ::: Python dev

I'm using Notepad++ for python development, and few days ago I found out about free Komodo Edit. I need Pros and Cons for Python development between this two editors... ...

How to setup setuptools for python 2.6 on Windows?

Is there any way to install setuptools for python 2.6 in Windows without having an .exe installer? There isn't one built at the moment, and the maintainer of setuptools has stated that it's probable be a while before he'll get to it. Does anyone know of a way to install it anyway? ...

How to quote a string value explicitly (Python DB API/Psycopg2)

Hello, For some reasons, I would like to do an explicit quoting of a string value (becoming a part of constructed SQL query) instead of waiting for implicit quotation performed by cursor.execute method on contents of its second parameter. By "implicit quotation" I mean: value = "Unsafe string" query = "SELECT * FROM some_table WHERE s...

Python - Setting / Getting Environment Variables and Addrs

I need to set an environment variable in Python and find the address in memory where it is located. Since it's on Linux, I don't mind about using libraries that only work consistently on Linux (if that's the only way). How would you do this? Edit: The scope of the problem is as follows: I'm trying to hack a program for class, and essent...

How can I translate the following filename to a regular expression in Python?

I am battling regular expressions now as I type. I would like to determine a pattern for the following example file: b410cv11_test.ext. I want to be able to do a search for files that match the pattern of the example file aforementioned. Where do I start (so lost and confused) and what is the best way of arriving at a solution that bes...