python

SDL/Pygame failing to load PNG images with cx_Freeze

I'm running Python 3.1 on Windows and I'm trying to distribute my Pygame script as an executable via cx_Freeze. Right now it seems to be working except that the exe build can't load any of my images: Cannot load image: C:\path\to\build\exe.win32-3.1\resources\image.png File is not a Windows BMP file Googling has revealed that this hap...

Strange altered behaviour when linking from .so file with ctypes in python

I am writing a program to handle data from a high speed camera for my Ph.D. project. This camera comes with a SDK in the form a .so file on Linux, for communicating with the camera and getting images out. As said it is a high speed camera delivering lots of data, (several GB a minute). To handle this amount of data the SDK has a very han...

Problem compiling mod_wsgi for python2.6 on Cent OS 5.3

I am running a website on CentOS 5.3. I understand centos will break if the default python 2.4 is upgraded. I followed this site (http://www.question-defense.com/2009/12/25/how-to-install-python-2-6-on-centos-5-without-breaking-yum) and got python 2.6 installed. Now if I run "python" it runs python2.4 and if I run "python26" it runs pyt...

pyodbc on SQL Server - How can I do an insert and get the row ID back?

I'm using pyodbc with SQL Server 2000. I want to be able to insert a row and get the auto incremented row id value back? Any ideas? Here's what I have so far: cursor.execute("insert into products(id, name) values ('pyodbc', 'awesome library')") cnxn.commit() ...

Extracting and integrating data from separate lists in Python

Hi, I have this code: cursor.execute( ''' SELECT id,DISTINCT tag FROM userurltag ''') tags = cursor.fetchall () T = [3,5,7,2,1,2,2,2,5,6,3,3,1,7,4] I have 7 groups names 1,...,7 . Each row in "tags" list corresponds to a row in "T" list.the values of "T" say that for example the first row in "tags" list belongs t...

get expando model properties in python for google-app-engine

How do I get all the properties from an expando model? (not just Model.properties()) I want to do something like this: ... recs = query.fetch( 100 ) for rec in recs: for name, value in rec.iteritem(): # figure out what, if any, expando properties are in this record but Model.iteritem() doesn't exist This seems like i...

Why is i++++++++i valid in python?

I "accidentally" came across this weird but valid syntax i=3 print i+++i #outputs 6 print i+++++i #outputs 6 print i+-+i #outputs 0 print i+--+i #outputs 6 (for every even no: of minus symbol, it outputs 6 else 0, why?) Does this do anything useful? Update (Don't take it the wrong way..I love python): One of Python's principle says...

Django select max id

Hi, given a standard model (called Image) with an autoset 'id', how do I get the max id? So far I've tried: max_id = Image.objects.all().aggregate(Max('id')) but I get a 'id__max' Key error. Trying max_id = Image.objects.order_by('id')[0].id gives a 'argument 2 to map() must support iteration' exception Any help? ...

tkinter integration with glib mainloop

Is it possible to integrate tkinter with glib mainloop ? ...

perl code to python code

can you convert this perl code to python code : $list = $ARGV[0]; open (PASSFILE, "$list") || die "[-] Can't open the List of password file !"; @strings = <PASSFILE>; close PASSFILE; Thanks ...

Google App Engine, Task Queues

How can I remove a task from a task queue? Is Google App Engine Task Queue removes the task from the queue after it is executed? ...

Streaming audio (YouTube)

Hello all, I'm writing a CLI for a music-media-platform. One of the features is going to be that you can directly play YouTube videos from the CLI. I don't really have an idea to do it but this one sounded the most reasonable: I'm going to use of those sites where you can download music from YouTube, e.g. http://keepvid.com/ - then I d...

Conditional operator in Mako using Pylons

In PHP, I often use the conditional operator to add an attribute to an html element if it applies to the element in question. For example: <select name="blah"> <option value="1"<?= $blah == 1 ? ' selected="selected"' : '' ?>> One </option> <option value="2"<?= $blah == 2 ? ' selected="selected"' : '' ?>> Two ...

How to tell process id within Python

Hey, I am working with a cluster system over linux (www.mosix.org) that allows me to run jobs and have the system run them on different computers. Jobs are run like so: mosrun ls & This will naturally create the process and run it on the background, returning the process id, like so: [1] 29199 Later it will return. I am writing a ...

how to pass in dynamic data to decorators

Hi, I am trying to write a base crud controller class that does the following: class BaseCrudController: model = "" field_validation = {} template_dir = "" @expose(self.template_dir) def new(self, *args, **kwargs) .... @validate(self.field_validation, error_handler=new) @expose() def post(self...

SWIG: Throwing exceptions from Python to C++

We've got an interface we've defined in C++ (abstract class, all functions pure virtual) which will be extended in Python. To overcome the cross-language polymorphism issues we're planning on using SWIG directors. I've read how to catch exceptions thrown from C++ code in our Python code here, here, here, and even on SO. It's fairly st...

Python 2.6 + PIL + Google App Engine issue

I am using OS X 1.6 snow leopard and I successfully got PIL installed. I am able to open terminal and type import Image without any errors. However, When using app engine I get Image error still saying that PIL is not installed. I am wondering if any of you have an thoughts as to how I can resolve this issue. -Matthew ...

Py2exe, PyQt4 and Postgre Driver (QPSQL)

Hi, I`m trying to freeze my application using Py2exe. My app uses PyQt4 and it apparently works fine with py2exe. But once I`ve uninstalled PyQt, it shows the following error: QSqlDatabase: QPSQL driver not loaded QSqlDatabase: available drivers: QPSQL7 QPSQL Which doesn't make any sense at all. The driver is available, but I can't us...

Using Python's ConfigParser to read a file without section name

Hello: I am using ConfigParser to read the runtime configuration of a script. I would like to have the flexibility of not providing a section name (there are scripts which are simple enough; they don't need a 'section'). ConfigParser will throw the NoSectionError exception, and will not accept the file. How can I make ConfigParser sim...

What's the best way to count unique visitors with Hadoop?

hey all, just getting started on hadoop and curious what the best way in mapreduce would be to count unique visitors if your logfiles looked like this... DATE siteID action username 05-05-2010 siteA pageview jim 05-05-2010 siteB pageview tom 05-05-2010 siteA pageview jim 05-05-2010 siteB pageview bob 05-05-2010 siteA ...