python

Python sockets suddenly timing out?

I came back today to an old script I had for logging into Gmail via SSL. The script worked fine last time I ran it (several months ago) but now it dies immediately with: <urlopen error The read operation timed out> If I set the timeout (no matter how long), it dies even more immediately with: <urlopen error The connect operation time...

time.sleep -- sleeps thread or process?

In Python for the *nix, does time.sleep() block the thread or the process? ...

What's the easiest non-memory intensive way to output XML from Python?

Basically, something similar to System.Xml.XmlWriter - A streaming XML Writer that doesn't incur much of a memory overhead. So that rules out xml.dom and xml.dom.minidom. Suggestions? ...

What Python GUI APIs Are Out There?

Simple question: What Python GUI API's are out there and what are the advantages of any given API? I'm not looking for a religious war here, I'm just wanting to get a good handle on all that is out there in terms of Python GUI APIs. ...

How do I persist to disk a temporary file using Python?

I am attempting to use the 'tempfile' module for manipulating and creating text files. Once the file is ready I want to save it to disk. I thought it would be as simple as using 'shutil.copy'. However, I get a 'permission denied' IOError: >>> import tempfile, shutil >>> f = tempfile.TemporaryFile(mode ='w+t') >>> f.write('foo') >>> shut...

Distributed python

Hi all, what is the best python framework to make distributed apps? For example to build a P2P app. Thanks ...

How do I read selected files from a remote Zip archive over HTTP using Python?

I need to read selected files, matching on the file name, from a remote zip archive using Python. I don't want to save the full zip to a temporary file (it's not that large, so I can handle everything in memory). I've already written the code and it works, and I'm answering this myself so I can search for it later. But since evidence su...

Image Processing, In Python?

I've recently come across a problem which requires at least a basic degree of image processing, can I do this in Python, and if so, with what? ...

What is the difference between range and xrange?

Apparently xrange is faster but I have no idea why it's faster (and no proof besides the anecdotal so far that it is faster) or what besides that is different about for i in range(0, 20): for i in xrange(0, 20): ...

Python implementation of Parsec?

I recently wrote a parser in Python using Ply (it's a python reimplementation of yacc). When I was almost done with the parser I discovered that the grammar I need to parse requires me to do some look up during parsing to inform the lexer. Without doing a look up to inform the lexer I cannot correctly parse the strings in the language....

Does an application-wide exception handler make sense?

Long story short, I have a substantial Python application that, among other things, does outcalls to "losetup", "mount", etc. on Linux. Essentially consuming system resources that must be released when complete. If my application crashes, I want to ensure these system resources are properly released. Does it make sense to do something...

Python reading Oracle path

On my desktop I have written a small Pylons app that connects to Oracle. I'm now trying to deploy it to my server which is running Win2k3 x64. (My desktop is 32-bit XP) The Oracle installation on the server is also 64-bit. I was getting errors about loading the OCI dll, so I installed the 32 bit client into C:\oracle32. If I add this...

How to associated the cn in an ssl cert of pyOpenSSL verify_cb to a generated socket

Hi All, I am a little new to pyOpenSSL. I am trying to figure out how to associate the generated socket to an ssl cert. verify_cb gets called which give me access to the cert and a conn but how do I associate those things when this happens: cli,addr = self.server.accept() ...

How to load a python module into a fresh interactive shell in Komodo?

When using PyWin I can easily load a python file into a fresh interactive shell and I find this quite handy for prototyping and other exploratory tasks. I would like to use Komodo as my python editor, but I haven't found a replacement for PyWin's ability to restart the shell and reload the current module. How can I do this in Komodo? ...

What is your favorite Python mocking library?

What is your single favorite mocking library for Python? ...

How do I use Django templates without the rest of Django?

I want to use the Django template engine in my (Python) code, but I'm not building a Django-based web site. How do I use it without having a settings.py file (and others) and having to set the DJANGO_SETTINGS_MODULE environment variable? If I run the following code: >>> import django.template >>> from django.template import Template, ...

What is your single favorite Python templating engine?

Name your single favorite Python templating engine (and describe why it's your favorite). ...

What is the best solution for database connection pooling in python?

I have developed some custom DAO-like classes to meet some very specialized requirements for my project that is a server-side process that does not run inside any kind of framework. The solution works great except that every time a new request is made, I open a new connection via MySQLdb.connect. What is the best "drop in" solution...

What is a metaclass in Python?

I´ve mastered almost all the Python concepts (well, let´s say there are just OO concepts :-)) but this one is tricky. I know it has something to do with introspection but it´s still unclear to me. So what are metaclasses? What do you use them for? Concrete examples, including snippets, much appreciated! ...

Python - easy way to add N seconds to a datetime.time?

Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so that 11:34:59 + 3 = 11:35:02, for example? These obvious ideas don't work: >>> datetime.time(11, 34, 59) + 3 TypeError: unsupported operand type(s) for +: 'datetime.time' and 'int' >>> datetime.time(11, 34, 59) + datetime.timede...