python

Binary buffer in Python

In Python you can use StringIO for a file-like buffer for character data. Memory-mapped file basically does similar thing for binary data, but it requires a file that is used as the basis. Does Python have a file object that is intended for binary data and is memory only, equivalent to Java's ByteArrayOutputStream? The use-case I have i...

pyGame within a pyGTK application

What is the best way to use PyGame (SDL) within a PyGTK application? I'm searching for a method that allows me to have a drawing area in the GTK window and at the same time being able to manage both GTK and SDL events. ...

Python module for converting PDF to text

Is there any python module to convert PDF files into text? I tried one piece of code found in Activestate which uses pypdf but the text generated had no space between and was of no use. ...

Python super class reflection

If I have Python code class A(): pass class B(): pass class C(A, B): pass and I have class C, is there a way to iterate through it's super classed (A and B)? Something like pseudocode: >>> magicGetSuperClasses(C) (<type 'A'>, <type 'B'>) One solution seems to be inspect module and getclasstree function. def magicGetSup...

Cleanest & Fastest server setup for Django

I'm about to deploy a mediumsized site powered by Django. I have a dedicated Ubuntu Server. I'm really confused over which serversoftware to use. So i thought to myself: why not ask stackoverflow. What i'm looking for is: Easy to set up Fast and easy on resources Can serve mediafiles Able to serve multiple djangosites on same server...

Is there any difference between "foo is None" and "foo == None"?

Is there any difference between: if foo is None: pass and if foo == None: pass The convention that I've seen in most Python code (and the code I myself write) is the former, but I recently came across code which uses the latter. None is an instance (and the only instance, IIRC) of NoneType, so it shouldn't matter, right? Are ther...

wxpython: How do I examine dragged data in OnDragOver?

I'm a bit perplexed by drag and drop in wxPython (but perhaps this questions pertains to drag and drop in other GUI frameworks as well). The frameworks provides a couple of callbacks (OnEnter and OnDragOver) that purportedly allow me to inform the system whether the current mouse position is a valid place to drop whatever it is that is b...

Where can I learn more about PyPy's translation function?

I've been having a hard time trying to understand PyPy's translation. It looks like something absolutely revolutionary from simply reading the description, however I'm hard-pressed to find good documentation on actually translating a real world piece of code to something such as LLVM. Does such a thing exist? The official PyPy documen...

Does PHP have an equivalent to this type of Python string substitution?

Python has this wonderful way of handling string substitutions using dictionaries >>> 'The %(site)s site %(adj)s because it %(adj)s' % {'site':'Stackoverflow', 'adj':'rocks'} 'The Stackoverflow site rocks because it rocks' I love this because you can specify a value once in the dictionary and then replace it all over the place in the ...

Is "safe_eval" really safe?

I'm looking for a "safe" eval function, to implement spreadsheet-like calculations (using numpy/scipy). The functionality to do this (the rexec module) has been removed from Python since 2.3 due to apparently unfixable security problems. There are several third-party hacks out there that purport to do this - the most thought-out solutio...

Most Pythonic way equivalent for: while ((x = next()) != END)

What's the best Python idiom for this C construct? while ((x = next()) != END) { .... } I don't have the ability to recode next(). update: and the answer from seems to be: for x in iter(next, END): .... ...

Best way to extract data from a FileMaker Pro database in a script?

My job would be easier, or at least less tedious if I could come up with an automated way (preferably in a Python script) to extract useful information from a FileMaker Pro database. I am working on Linux machine and the FileMaker database is on the same LAN running on an OS X machine. I can log into the webby interface from my machine. ...

What refactoring tools do you use for Python ?

I have a bunch of classes I want to rename. Some of them have names that are small and that name is reused in other class names, where I don't want that name changed. Most of this lives in Python code, but we also have some XML code that references class names. Simple search and replace only gets me so far. In my case, I want to rena...

What's the best way to use web services in python?

I have a medium sized application that runs as a .net web-service which I do not control, and I want to create a loose pythonic API above it to enable easy scripting. I wanted to know what is the best/most practical solution for using web-services in python. Edit: I need to consume a complex soap WS and I have no control over it. ...

How do I create an xml document in python

It's my first time generating xml with python, and the python documentation, which is generally good, is really lacking for xml creation...here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document() node = doc.createElement('foo') node.innerText = 'bar' doc.appendChild(node) return doc if...

Python distutils - does anyone know how to use it?

Hello, I wrote a quick program in python to add a gtk GUI to a cli program. I was wondering how I can create an installer using distutils. Since it's just a GUI frontend for a command line app it only works in *nix anyway so I'm not worried about it being cross platform. my main goal is to create a .deb package for debian/ubuntu users,...

Python exercises to hone your skills

Is there a place with little coding projects you can do to hone your skills? Preferably with answers to compare your code to and/or look at if you can't figure it out. a good example of such a site is http://www.hackthissite.org, which has little web security tutorials to help you learn about vulnerabilities and ways people might hack a...

Trackback/Pingback libraries for Python/Ruby?

I'm considering writing my own blog but I have had some issues deciding for an appropriate software. From my survey so far I have concluded that the easiest, most feature-rich, free software is Wordpress. However, I would very much like to use several components written in either Python or Ruby, e.g. either Pygments or CodeRay as a sourc...

Install Python to match directory layout in OS X 10.5

The default Python install on OS X 10.5 is 2.5.1 with a fat 32 bit (Intel and PPC) client. I want to setup apache and mysql to run django. In the past I have run apache and mysql to match this install in 32 bit mode (even stripping out the 64 bit stuff from apache to make it work). I want to upgrade Python to 64 bit. I am completely com...

How do threads work in Python, and what are common Python-threading specific pitfalls?

I've been trying to wrap my head around how threads work in Python, and it's hard to find good information on how they operate. I may just be missing a link or something, but it seems like the official documentation isn't very thorough on the subject, and I haven't been able to find a good write-up. From what I can tell, only one thread...