python

How to find the number of parameters to a Python function from C?

I'm using the Python C API to call Python functions from my application. I'd like to present a list of functions that could be called and would like to be able to limit this list to just the ones with the expected number of parameters. I'm happy that I can walk the dictionary to extract a list of functions and use PyCallable_Check to fi...

How to update the twisted framework

I can see from the latest 8.2 (almost 1200 lines of code) twisted that I am missing something: http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/jabber/xmlstream.py My copy (697 lines from 3 years ago) is in: /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/words/protocols/jabber/xmlst...

How do I tell a Python script (cygwin) to work in current (or relative) directories?

I have lots of directories with text files written using (g)vim, and I have written a handful of utilities that I find useful in Python. I start off the utilities with a pound-bang-/usr/bin/env python line in order to use the Python that is installed under cygwin. I would like to type commands like this: %cd ~/SomeBook %which pythonU...

Efficiently importing modules in Django views

Hi all, I was wondering - how do people handle importing large numbers of commonly used modules within django views? And whats the best method to do this efficiently? For instance, I've got some views like, admin_views.py search_views.py . . and from what I've seen, every one of them needs to use HttpResponse or other such commonly ...

Cleaning up nested Try/Excepts

I've just written a chunk of code that strikes me as being far more nested than is optimal. I'd like advice on how to improve the style of this, particularly so that it conforms more with "Flat is better than nested." for app in apps: if app.split('.', 1)[0] == 'zc': #only look for cron in zc apps try: a = app + ...

Fake a cookie to scrape a site in python

The site that I'm trying to scrape uses js to create a cookie. What I was thinking was that I can create a cookie in python and then use that cookie to scrape the site. However, I don't know any way of doing that. Does anybody have any ideas? ...

python sqlalchemy parallel operation

HI,i got a multi-threading program which all threads will operate on oracle DB. So, can sqlalchemy support parallel operation on oracle? tks! ...

Set Django IntegerField by choices=... name

When you have a model field with a choices option you tend to have some magic values associated with human readable names. Is there in Django a convenient way to set these fields by the human readable name instead of the value? Consider this model: class Thing(models.Model): PRIORITIES = ( (0, 'Low'), (1, 'Normal'), (2, '...

In Python, is there a way to detect the use of incorrect variable names; something like VB's "Option Explicit"?

I do most of my development in Java and C++ but recently had to write various scripts and picked up Python. I run python from the command line on scripts; not in interactive mode. I'm wondering if I like a lot of things about the language, but one thing that keeps reducing my productivity is the fact that I get no advance warning if I ...

geodjango + PostGIS = GPL?

I always get confused with licenses, I'm reading up again, but I'm sure someone out there already understands this and may be able to explain it more clearly. I'm trying to get my company to use geodjango, and being a typical large enterprise company they don't want to open-source the resulting project. And therefore opposed to touchin...

Python MySQLdb exceptions

Hi All, Just starting to get to grips with python and MySQLdb and was wondering Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query? What exceptions should i be catching on any of these blocks? thanks for any help Cheers Mark ...

Caching PHP script outputs on the client side

I have a php script that outputs a random image each time it's called. So when I open the script in a web browser, it shows one image and if I refresh, another image shows up. I'm trying to capture the correct image from visiting the web site through a command line (via mechanize). I used urllib2.urlopen(...) to grab the image, but each...

How Do I Use Raw Socket in Python?

I am writing an application to test a network driver for handling corrupted data. And I thought of sending this data using raw socket, so it will not be corrected by the sending machine's TCP-IP stack. I am writing this application solely on Linux. I have code examples of using raw sockets in system-calls, but I would really like to kee...

Most "pythonic" way of organising class attributes, constructor arguments and subclass constructor defaults?

Being relatively new to Python 2, I'm uncertain how best to organise my class files in the most 'pythonic' way. I wouldn't be asking this but for the fact that Python seems to have quite a few ways of doing things that are very different to what I have come to expect from the languages I am used to. Initially, I was just treating classe...

Turbogears 2 vs Django - any advice on choosing replacement for Turbogears 1?

I have been using Turbogears 1 for prototyping small sites for the last couple of years and it is getting a little long in the tooth. Any suggestions on making the call between upgrading to Turbogears 2 or switching to something like Django? I'm torn between the familiarity of the TG community who are pretty responsive and do pretty good...

How to debug in Django, the good way?

So, I started learning to code in Python and later Django. The first times it was hard looking at tracebacks and actually figure out what I did wrong and where the syntax error was. Some time has passed now and some way along the way, I guess I got a routine in debugging my Django code. As this was done early in my coding experience, I s...

Is there a way to know which versions of python are supported by my code?

You may know the Windows compliance tool that helps people to know if their code us supported by any version of the MS OS. I am looking something similar for Python. I am writing a lib with Python 2.6 and I realized that it was not compatible with Python 2.5 due to the use of the with keyword. I would like to know if there is a simp...

List of values to a sound file

Guys, Im trying to engineer in python a way of transforming a list of integer values between 0-255 into representative equivalent tones from 1500-2200Hz. Timing information (at 1200Hz) is given by the (-1),(-2) and (-3) values. I have created a function that generates a .wav file and then call this function with the parameters of each to...

Is there a database implementation that has notifications and revisions?

I am looking for a database library that can be used within an editor to replace a custom document format. In my case the document would contain a functional program. I want application data to be persistent even while editing, so that when the program crashes, no data is lost. I know that all databases offer that. On top of that, I wa...

What is a good python-based Webshop Software?

I am currently evaluating for an eCommerce project. Is there any good Python based webshop software. Are there any personal experiences people can share? Until now I have only found: http://www.satchmoproject.com/ Coming from the PHP world finding only ONE project seams akward to me. Does anybody have experience with Satchmo? Ar...