python

Select mails from inbox alone via poplib

I need to download emails from the gmail inbox only using poplib.Unfortunately I do not see any option to select Inbox alone, and poplib gives me emails from sent items too. How do I select emails only from inbox? I dont want to use any gmail specific libraries. ...

Best practice for integrating CherryPy web-framework, SQLAlchemy sessions and lighttpd to serve a high-load webservice

I'm developing a CherryPy FastCGI server behind lighttpd with the following setup to enable using ORM SQLAlchemy sessions inside CherryPy controllers. However, when I run stress tests with 14 concurrent requests for about 500 loops, it starts to give errors like AttributeError: '_ThreadData' object has no attribute 'scoped_session_class'...

Dump memcache keys from GAE SDK Console?

In the "Memcache Viewer", is there any way to dump a list of existing keys? Just for debugging, of course, not for use in any scripts! I ask because it doesn't seem like the GAE SDK is using a "real" memcache server, so I'm guessing it's emulated in Python (for simplicity, as it's just a development server).. This would mean there is a ...

python conditional lock

How can I implement conditional lock in threaded application, for instance I haw 30 threads that are calling function and for most off the time all threads can access is simultaneous, but depending on function input there can be condition when only one thread can do that one thing. (If value for input is repeated and some thread is stil...

wxpython auinotebook close tab event.

What event is used when I close a tab in an auinotebook? I tested with EVT_AUINOTEBOOK_PAGE_CLOSE(D). It didn't work. I would also like to fire a right click on the tab itself event. Where can I find all the events that can be used with the aui manager/notebook? Might just be my poor searching skills, but I can't find any lists over th...

How can I pass all the parameters to a decorator?

I tried to trace the execution of some methods using a decorator. Here is the decorator code: def trace(func): def ofunc(*args): func_name = func.__name__ xargs = args print "entering %s with args %s" % (func_name,xargs) ret_val = func(args) print "return value %s" % ret_val print "exiting %s" % (...

Store Django form.cleaned_data in null model field?

I have a django model, which has a int field (with null=True, blank=True). Now when I get a form submit from the user, I assign it like so: my_model.width= form.cleaned_data['width'] However sometimes I get an error: ValueError: invalid literal for int() with base 10: '' I was wandering if it's the blank ('') string value that gets...

Loading bundled python framework dependencies using only python

I've come across this question but I don't like the solution that is presented. Shell scripting is operating system dependent. Is there a python solution to this problem? I'm not looking for python to machine code compilers, just a way to modify the include paths with python. ...

File editing in python

I wrote a little python program as a personal utility to help me with some refactoring. It's similar to unix replace, except it supports regular expressions and operates on all files in a directory and (optionally) all subdirectories. The problem is I'm not replacing in place. I'm opening files, passing the contents into memory, and t...

Validating a Unicode Name

In ASCII, validating a name isn't too difficult: just make sure all the characters are alphabetical. But what about in Unicode (utf-8) ? How can I make sure there are no commas or underscores (outside of ASCII scope) in a given string? (ideally in Python) ...

How to find out the summarized text of a given URL in python / Django ?

How to find out the summarized text for a given URL? What do i mean by summarized text? Merck $41.1 Billion Schering-Plough Bid Seeks Science Link Descrption Merck & Co.’s $41.1 billion purchase of Schering-Plough Corp. adds experimental drugs for blood clots, infections and schizophrenia and allows the companies to speed research o...

What's the difference between list and tuples in Python?

What's the difference? What are the advantages / disadvantages of tuples / lists? ...

How do I find the Windows common application data folder using Python?

I would like my application to store some data for access by all users. Using Python, how can I find where the data should go? ...

Is it possible to write to a python frame object as returned by sys._getframe() from python code running within the interpreter?

Apropos of This question, there is a bit of scaffolding within the interpreter to inspect frame objects, which can be retrieved by sys._getframe(). The frame objects appear to be read only, but I can't find anything obvious in the docs that explicitly states this. Can someone confirm whether these objects are writeable (in some way) or...

How to remove an element from a list by index in Python?

How to remove an element from a list by index in Python? I found the list.remove method but say I want to remove the last element, how do I do this? It seems like the default remove searches the list, but I don't want any search to be performed. ...

How can I use named arguments in a decorator?

If I have the following function: def intercept(func): # do something here @intercept(arg1=20) def whatever(arg1,arg2): # do something here I would like for intercept to fire up only when arg1 is 20. I would like to be able to pass named parameters to the function. How could I accomplish this? Here's a little code sample : d...

Form Field API?

I am iterating through list of form fields. How do I identify the type of each field? For checkbox I can call field.is_checkbox...are there similar methods for lists, multiplechoicefields etc. ? Thanks ...

Using Python to get Windows system internals info

I'd like to write some quick Python code to assess the CPU, memory, disk, and networking usage of my Windows XP system. Are there existing Python libraries that would allow me to access that information? Or, are there DLL's that I can call from Python? (If so, a code sample would be appreciated) ...

Next step after PHP: Perl or Python?

It might seem it has been asked numerous times, but in fact it hasn't. I did my research, and now I'm eager to hear others' opinions. I have experience with PHP 5, both with functional and object oriented programming methods. I created a few feature-minimalistic websites. Professionals may agree about PHP not being a programming langua...

Django forms

I had asked a question pertaining to this. But I think it would be better to ask my question directly. I have a "User" table with manytomany relationship with two other tables "Domain" and "Groups". So in the admin interface I see the Groups and Domains as 2 ModelMultipleChoiceFields. But I want to present them on the UI in a more user f...