python

using wsgiref.simple_server in unittests

I has some function like this one: URL = 'http://localhost:8080' def func(): response = urlopen(URL) return process(response) And i want to test it with unittest. I do something like this: from wsgiref.simple_server import make_server def app_200_hello(environ,start_response): stdout = StringIO('Hello world') star...

Django: Calling custom Model method from Form clean method. "Unbound Method"?

I'm having a problem while trying to call a custom Model method from my Form clean method. Here is [part of] my model: http://dpaste.com/hold/12695/ Here is my Form: http://dpaste.com/hold/12699/ I'm specifically having a problem with line 11 in my Form: nzb_data = File.get_nzb_data(nzb_absolute) This raises the following error: Typ...

svg diagrams using python

I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found python-gd, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for this purpose. I am mostly thinking about simple line graphs, something like this: ...

Django Admin

I am using Django admin for managing my data. I have a Users, Groups and Domains tables Users table has many to many relationship with Groups and Domains tables. Domains table has one to many relationship with Groups table. and when I save the User data through admin I also need some addtional database updates in the users_group and the...

Python urllib2, basic HTTP authentication, and tr.im

I'm playing around, trying to write some code to use the http://tr.im APIs (http://tr.im/api/) to shorten a URL. After reading http://docs.python.org/library/urllib2.html, I tried: TRIM_API_URL = 'http://api.tr.im/api' auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(realm='tr.im', ...

Web frameworks performance comparison

I'm looking for real life benchmarks comparing web frameworks based on dynamic languages (Python, Ruby, Groovy and Lua). Even better if they're compared up against classic solutions based on PHP, Java, ASP.NET maybe even Perl. I'm particularly interested in: Django Ruby on Rails Grails Zend Framework Struts2 EDIT: As for Sean's answe...

Visual Studio 2005 Build of Python with Debug .lib

Hello, I am looking for the Visual Studio 2005 build of Python 2.4, 2.5 or 2.6, I also need the python2x_d.lib (the debug version of the .lib) since I embed the interpreter into my app and the python libs implicitly link to the python2x_d.lib with pragmas (grrr). Any hints where I can find those builds ? Regards, Paul ...

code documentation for python

What is out there on conventions and tools for documenting python source code? ...

What is the best way to implement nested dictionaries in Python?

I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this: {'new jersey': {'mercer county': {'plumbers': 3, 'programmers': 81}, 'middlesex county': {'programmers': 81, 'salesmen': 62}}, 'new york': {'queen...

Django: Open uploaded file while still in memory; In the Form Clean method?

I need to validate the contents of an uploaded XML file in my Form clean method, but I'm unable to open the file for validation. It seams, in the clean method, the file hasn't yet been moved from memory (or the temporary directory) to the destination directory. For example the following code doesn't work because the file hasn't been mov...

Inserting A Heading Into A Django Form

I would like my form to output something like this: Name: ___________ Company: ___________ Interested in ------------- Foo: [ ] Bar: [ ] Baz: [ ] That is to say, I would like to have the 'Interested In' title inserted in the middle of my form output. One way of doing this would be to write out the template code for each field, and i...

tell whether a character is a combining diacritic mark

if you're looping though the chars a unicode string in python (2.x), say: ak.sɛp.tɑ̃ How can you tell whether the current char is a combining diacritic mark? For instance, the last char in the above string is actually a combining mark: ak.sɛp.tɑ̃ --> ̃ ...

Literal XML (unescaped) parameter in ZSI

I'm using ZSI to talk to a SOAP web service. One of the methods expects a literal XML string wrapped in a CDATA tag. How can I make it so that ZSI will NOT escape the string? For example, I want to pass the following as a parameter: <query> <name>Elmer Fudd</name> <age unit="years">33</age> <job>Wabbit Hunter</job> </query> I d...

python: problem using call.subprocess to use a file after writing it

In python I am trying to write a script that will edit text files and then run executables that use those text files. It basically entails 1)opening and reading/writing to a text file, and 2)using the file I just wrote in a bash command. Here is a simple example: import subprocess # write file a = ['1\n','2\n','3\n','4\n','5th and fi...

What's different between Python and Javascript regular expressions?

Are Python and JavaScript regular expression syntax identical? If not, then: What are the important differences between them Is there a python library that "implements" JavaScript regexps? ...

SELECT * in sqlalchemy?

Is it possible to do SELECT * in sqlalchemy? Edit: Specifically, SELECT * WHERE foo=1 ...

How can I run an external command asynchronously from Python?

I need to run a shell command asynchronously from a Python script. By this I mean that I want my Python script to continue running while the external command goes off and does whatever it needs to do. I read this post: http://stackoverflow.com/questions/89228/how-to-call-external-command-in-python I then went off and did some te...

Python Profiling in Eclipse

This questions is semi-based of this one here: http://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script I thought that this would be a great idea to run on some of my programs. Although profiling from a batch file as explained in the aforementioned answer is possible, I think it would be even better to have this op...

Unable to make each sentence to start at a new line in LaTex by AWK/Python

I have a long document in LaTex, which contains paragraphs. The paragraphs contain sentences such that no subsequent sentence start at a new line. How can you make each subsequent sentence to start at a new line in my .tex file? My attempt to the problem We need to put \n to the end of Sentence B where Sentence B has Sentence A before...

Django form - set label

I have a form that inherits from 2 other forms. In my form, I want to change the label of a field that was defined in one of the parent forms. Does anyone know how this can be done? I'm trying to do it in my __init__, but it throws an error saying that "'RegistrationFormTOS' object has no attribute 'email'". Does anyone know how I can ...