python

Python - convert list of tuples to string

Which is the most pythonic way to convert a list of tuples to string? I have: [(1,2), (3,4)] and I want: "(1,2), (3,4)" My solution to this has been: l=[(1,2),(3,4)] s="" for t in l: s += "(%s,%s)," % t s = s[:-1] Is there a more pythonic way to do this? ...

How to write a JIT library?

I've browsed through many JIT libraries. But I'd like to learn how to write one. Softwire looked like nice. Though what the emitter interface should do? Can I do something better than existing libraries? How do I support inline caching? ...

Forcing a variable to be an integer

errors = int(0) for i in range(len(expectedData)): if data[i] != expectedData[i]: errors += int(binary_compare(data[i], expectedData[i])) return errors I have the above code which I am trying to use to calculate some integer (number of errors) for some data. I have casted everything I can see possible as an integer, yet th...

Sum fields in sqlAlchemy

I recently upgraded to the most recent version of sqlalchemy and some of my code no longer works. I'm having difficulty finding how to fix it and could use a hand. Previously the query appeared as so. self.db.query(Drive).filter(Drive.package_id==package.package_id)\ .filter(Drive.wipe_end!=None).sum(Drive.wipe_end - Drive.wipe_sta...

Write a Plugin in Python for audio

I have written a script that on execution lets the user record a message by accessing their microphone and stores it. I want to make this script useable over my website, which will require me to write a plug-in for the browser. Is there a good tutorial that will teach me how to write this plug in and set it up. is there another way. ...

define *struct in ctypes

I need to convert regexitem *regex to ctype variable, any ideas? C function expects func(regexitem *regex) char *regex1Groups[] = { "a","b","x","s" ,NULL}; char *regex2Groups[] = { "l" ,NULL}; regexitem regex[] = { {"bla", regex1Groups,4 }, {"bla2",regex2Groups,1 } }; First i defined class ...

My function takes negative time to complete. What in the world happened?

I'm posing this question mostly out of curiosity. I've written some code that is doing some very time intensive work. So, before executing my workhorse function, I wrapped it up in a couple of calls to time.clock(). It looks something like this: t1 = time.clock() print this_function_takes_forever(how_long_parameter = 20) t2 = time.clock...

Any Multi-Format Document Reading Lib for Python /or C?

Is there any good Document Parsing Lib , in C or Python? I am trying to Parse Strings from Documents - PDF, Word Doc/Docx , Excel xls/x , PPT, ODF, and also Mac Formats. Please Recommand Solutions that would also work in Linux/Unix enviorment. ...

XML to/from a Python dictionary

I need to use Python 2.4.4 to convert XML to and from a Python dictionary. All I need are the node names and values, I'm not worried about attributes because the XML I'm parsing doesn't have any. I can't use ElementTree because that isn't available for 2.4.4, and I can't use 3rd party libraries due to my work environment. What's the easi...

Python utf-8 handling

Hi, I am using Python 2.6.1 and am having utf-8 related problem with my code. This problem is reproducible with this code: # -*- coding: utf-8 -*- import os, sys import string, time import codecs, re bDATA='"Domenick Lombardozzi","Eddie Marsan","Isaach De Bankolé","John Hawkes"' print (bDATA) fileObj = codecs.open("btvresp1.txt", "r", ...

python dbus problem

I have a problem with dbus and python. Running python from the command line, telling it import dbus and then systembus = dbus.SystemBus() results in no errors, nor does running a program written by a friend which also uses the exact same code. However, when running a program I'm trying to write, I get this error: Traceback (most recent ...

modwsgi - Precompiled Binaries for Python 2.4?

I'm trying to install Django using Apache and modwsgi on Windows XP. The problem is our whole development environment uses Python 2.4. This page explains how to install modwsgi on Windows but it doesn't link to any precompiled binaries for Python 2.4. Anyone know of anything, or a workaround? ...

django forms into database

hey guys, im trying to make a volunteer form, that takes info such as name, last name, etc. and i want to save that info into my database (MySQL), so that it can be retrieved later on . ...

algorithm design in python

I need to know about the uniform cost search algorithm. In the uniform cost solution, we find a node that has the lowest cost. But there can be other nodes that have less cost than the previous one.Do we need use some buffer to keep the lowest value in that , so that we can get the lowest cost from the whole tree??I need some pseducode ...

How to resume a Selenium RC test after a computer sleep?

When I put my Mac to sleep while an interactive Python session with a selenium instance and corresponding browser is running, after waking up the browser (or selenium server?) are no longer responding to any commands from the Python shell. This forces me to restart the browser, losing the state of my test. Is there a way to overcome th...

How to walk a tar.gz file that contains zip files without extraction

I have a large tar.gz file to analyze using a python script. The tar.gz file contains a number of zip files which might embed other .gz files in it. Before extracting the file, I would like to walk through the directory structure within the compressed files to see if certain files or directories are present. By looking at tarfile and zip...

Python make systems

What are the benefits and problems with the various Python make-like systems? note We're using the denotations '(+)' and '(-)' respectively at the beginning of list items to indicate benefits and problems. So far I'm aware of buildit was previously known as pymake (-) seems to be obsolescing: last release was in late 2007 zc.build...

Reading files and writing to database in django

I have a Django app that opens a file, continuously reads it, and at the same time writes data to a Postgres database. My issue is that whenever I open a file, file = open(filename, 'r') I am unable to also create new things in the database, Message.objects.create_message(sys, msg) That should create a database entry with two str...

position contents of array.array into heap

I have a simple byte array I've filled with a x86 -program. Which I need to execute at runtime. """ Produces a simple callable procedure which returns a constant. """ from array import array simple = array('B') # mov rax, 0x10 simple.extend((0x81, 0xc0, 0x10, 0x0, 0x0, 0x0)) # ret simple.append(0xc3) Now, to get this running, I'...

Multiple select() syscalls from one thread in Python.

I'm using a couple of Python libraries, and they both use a select() syscall. I was wondering if it was safe to have two select() syscalls from within the same thread (assuming there are no shared descriptors between them)? ...