python

Override save_model on Django InlineModelAdmin

I have a model that has a user field that needs to be auto-populated from the currently logged in user. I can get it working as specified here if the user field is in a standard ModalAdmin, but if the model I'm working with is in an InlineModelAdmin and being saved from the record of another model inside the Admin, it won't take. ...

The correct case&format of variable and methods and for Python

So I know some languages have expected conventions. PHP - underscore_case() [for the most part, lolo] Java - camelCase() C# - PascalCase() etc. What's the "Pythonic" naming convention? I know it doesn't matter in the end but just wondering if there is a "best practice" way that most modules are done in. ...

Run all unit test in Python directory

So I have a directory that contains my Python unit test. Each unit test module is of the form "test_*.py". I am attempting to make a file called "all_test.py" that will, you guessed it, run all files in aforementioned test form and return the result. I have tried two methods so far, both have failed, I will show the two methods, and hope...

Django ease of building a RESTful interface

I'm looking for an excuse to learn Django for a new project that has come up. Typically I like to build RESTful server-side interfaces where a URL maps to resources that spits out data in some platform independent context, such as XML or JSON. This is rather straightforward to do without the use of frameworks, but some of them such as R...

Post XML to .net web service

Hello, I am a big noob to start off. I typically use SOAPsonar to get a WSDL and then fill out the XML and then POST it Now I want to be able to use Python to take an XML file and POST it to the same URL that I would use in SOAPSonar - Basically I want to do the same thing I do in SOAPSonar but, using Python. I sure could use some help...

Packaging resources with setuptools/distribute

I'm developing an Python egg that has several .txt dependencies (they're templates used to generate files by the egg itself), and I'm struggling to get those dependencies copied to site-packages during setup.py install. According to the distribute documentation... Filesystem of my package: setup.py package |--- __init__.py |--- main.py...

What is a suitable buffer for Python's struct module

In Python I'm accessing a binary file by reading it into a string and then using struct.unpack(...). Now I want to write to that string using struct.pack_into(...), but I get the error "Cannot use string as modifiable buffer". What would be a suitable buffer for use with the struct module? ...

Unzipping part of a .gz file using python

So here's the problem. I have sample.gz file which is roughly 60KB in size. I want to decompress the first 2000 bytes off this file. I am running into CRC check failed error cuz I guess the gzip CRC field appears at the end of file, and it requires the entire gzipped file to decompress. Is there a way to get around this? I dont care abou...

Lexical Analysis of Python Programming Language

Does anyone know where a FLEX or LEX specification file for Python exists? For example, this is a lex specification for the ANSI C programming language: http://www.quut.com/c/ANSI-C-grammar-l-1998.html FYI, I am trying to write code highlighting into a Cocoa application. Regex won't do it because I also want grammar parsing to fold code...

Reading Alpha of a PNG Pixel. Fast way via pure Python?

I am having an issue with an embedded 64bit Python instance not liking PIL. Before i start exhausting more methods to get a compiled image editor to read the pixels for me (such as ImageMagick) i am hoping perhaps anyone here can think of a purely Python solution that will be comparable in speeds to the compiled counterparts. Now i am a...

UnicodeEncodeError on MySQL insert in Python

I used lxml to parse some web page as below: >>> doc = lxml.html.fromstring(htmldata) >>> element in doc.cssselect(sometag)[0] >>> text = element.text_content() >>> print text u'Waldenstr\xf6m' Why it prints u'Waldenstr\xf6m' but not "Waldenström" here? After that, I tried to add this text to a MySQL table with UTF-8 character set a...

PyQt display fullscreen image

I'm using PyQt to capture my screen with QPixmap.grabWindow(QApplication.desktop().winId()) and I was wondering if there was a way I could display my screengrab fullscreen (no window borders, etc.) I'm trying to find a way to desaturate my display with PyQt ...

Making BeautifulSoup ignore contents inside script tags

I have been trying to get BeautifulSoup (3.1.0.1)to parse a html page that has a lot of javascript that generates html inside tags. One example fragment looks like this : <html><head><body><div> <script type='text/javascript'> if(ii > 0) { html += '<span id="hoverMenuPosSepId" class="hoverMenuPosSep">|</span>' } html += '<div class=...

Twisted Spread suitable for multiplayer racing sim?

Do you think that Twisted Spread may be suitable (in terms of performance) for a multiplayer racing simulator? The rest of the application is based on Python-Ogre. Can Perspective Broker run upon (reliable?) UDP? ...

Python: next() function

I'm learning Python from a book, and I came across this example: M = [[1,2,3], [4,5,6], [7,8,9]] G = (sum(row) for row in M) # create a generator of row sums next(G) # Run the iteration protocol Since I'm an absolute beginner, and the author hasn't provided any explanation of the example or the next() function, I don't unde...

Django error opening SQLite3 db file on when running off Apache

Hey guys, I got this error: OperationalError at / unable to open database file Things I've tried so far are setting the absolute path of my dev.db file in the settings.py. I've tried adding www-data to my admin group and setting the group of my project folder to the admin, and setting the group to www-data, none of which solved the p...

pymedia.audio.sound - How do I get up and running with this module?

Im trying to get my hands on this pymedia.audio.sound module and have attempted to get it several times from python.org, but I think I am doing something wrong like. Any help greatly appreciated. Im running Windows XP, Python 2.5 and its running fine, but how do I download and where do I extract the new module to be able to use it? Ap...

Grokking Timsort

There's a (relatively) new sort on the block called Timsort. It's been used as Python's list.sort, and is now going to be the new Array.sort in Java 7). There's some documentation and a tiny Wikipedia article describing the high-level properties of the sort and some low-level performance evaluations, but I was curious if anybody can pro...

Convert PyQt to PIL image

I have an image in a QImage and I want to process it in PIL before I display it. While the ImageQT class lets me convert a PIL Image to a QImage, there doesn't appear to anything to go from a QImage to a PIL Image. ...

`from QTKit import *` causes a 'FAILED TO establish the default connection to the WindowServer' in PyObjC application

I've been trying out PyObjC and I can't seem to get the QTKit imports to work. If I import QTKit like so: from QTKit import * I get a flood of errors: [Session started at 2009-11-13 21:03:49 -0600.] _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL. 2009-11-13 21:03:...