python

How to open a Pyqt 3.3 ui file with QtDesigner 4?

Hello, I've a PyQt 4 installed (I can't find PyQt 3 for Windows) and I would like to open a QtDesigner ui file which has been created with QtDesigner 3.3. When I open this file I've the following message: Please use uic3 -convert to convert to Qt4 Unfortunately, I don't see the uic3 tool in the bin folder of my install. Does anybody...

What do (lambda) function closures capture in Python?

Recently I started playing around with Python and I came around something peculiar in the way closures work. Consider the following code: adders= [0,1,2,3] for i in [0,1,2,3]: adders[i]=lambda a: i+a print adders[1](3) It builds a simple array of functions that take a single input and return that input added by a number. The funct...

List minimum in Python with None?

Is there any clever in-built function or something that will return 1 for the min() example below? (I bet there is a solid reason for it not to return anything, but in my particular case I need it to disregard None values really bad!) >>> max([None, 1,2]) 2 >>> min([None, 1,2]) >>> ...

python csv - export data and format color, text format, etc..

Hi, I'm exporting data from python with the csv library which works pretty good. After a web-search I can not find any information about how to format the exported data with python. For example. I export a csv row within python like this. for hour_record in object_list: row = list() for field in fields: ...

Regex for Time Format

Regex needed for a time of the format: 12-02-30T00:59:43. Also, I've not managed to find any decent websites or books that contain good explanations or reference material for regular expressions. Can anyone recommend any? ...

Generating recurring dates using python?

How can I generate recurring dates using Python? For example I want to generate recurring date for "Third Friday of every second month". I want to generate recurring dates for daily, weekly, monthly, yearly (i.e., same as the recurrence function in Outlook Express). ...

Is the python mechanize cache feature the same as normal browser cache feature?

In its document, it says "This caching behaviour can be avoided by using Mechanize.OpenerDirector". Does this cache influence next request of the same page? ...

Python's equivalent to PHP's strip_tags?

Python's equivalent to PHP's strip_tags? http://php.net/manual/en/function.strip-tags.php ...

Garbage collection of object after exception

I have observed that after an exception I have an object for which constructor is not called, which causes a lock to be held. What is the best way to improve the situation? Would calling del in an except block be the solution? b=BigHash(DB_DIR, url) meta = bdecode(b.get()) return meta b holds a lock which is released on destruction (i...

Weak reference callback is not called because of circular references

I'm trying to write a finalizer for Python classes that have circular references. I found out that weak reference callbacks are the way to go. Unfortunately, it seems the lambda I use as a callback is never called. For example, running this code: def del_A(name): print('An A deleted:' + name) class A(object): def __init__(self,...

Looking for example GUI applications written in Python for the iPhone.

Hey! I have a little script I wrote in python and it actually works on the iPhone via the terminal. I am looking for code snippets or documentation for the GUI writing for the iPhone - Actually what I need is to implement an input and some output. nothing fancy - for now. I have found this page: http://www.saurik.com/id/5 but as i und...

How to run a piece of code in every view in django?

Hello there! I need to check user authorization in every view of one of my Django apps (I don't use Django's built in auth system) and redirect user to a "login please" page, if authorization has failed. Code looks like this: try: admin_from_session = request.session['admin']; admin = Administrator.objects.get(login = admin_fr...

join lists based on common head or tail

What is the fastest way to solve the following I will to join several lists based on common head or tail input = ([5,6,7], [1,2,3], [3,4,5], [8, 9]) output = [1, 2, 3, 4, 5, 6, 7] ...

Updating a de-normalized attribute automatically with an AttributeExtension

I am having some troubles with the AttributeExtension of SQLAlchemy. Actually I am storing a de-normalized sum attribute in the Partent table, because I need it quite often for sorting purposes. However, I would like the attribute to get updated whenever the value of one of it's children is changed. Unfortunately, the set() method of t...

How to see possible combinations of a given number in python

Hi, in Python I wanting see all the possible combination's of a number, but limiting to 0's and 1's... So for example the result of some loop would be: 0000 0001 0011 0111 1111 1000 and so on. What python algorithm would best suite this? ...

how to encode/decode escape sequence characters in python

how to encode/decode escape sequence character '\x13' in python into a character that is valid in a RSS or XML. use case is, I am getting data from arbitrary sources and making a RSS feed for that data. The data source sometimes have escape sequence character which is breaking my RSS feed. So how can I sanitize the input data with e...

Production-ready PayPal, 2CO and Authorize.Net libraries for Python/Django?

Seems that Python lacks e-commerce solutions compared to PHP and C#. Any production-ready PayPal, 2CO and Authorize.Net libraries for Python/Django? EDIT: http://github.com/johnboxall/django-paypal http://www.djangosnippets.org/snippets/969/ E-commerce: http://www.satchmoproject.com/ http://code.activestate.com/recipes/456361/ http://...

how to have global variables among different modules in Python

hello, I investigated that scope of global variables in python is limited to the module. But I need the scope to be global among different modules. Is there such a thing? I played around __builtin__ but no luck. thanks in advance! ...

Rollback error when saving incorrect data into column

I have a fairly standard SQLA setup with the exception of reflecting the table I'm using. Here's the code: import sqlalchemy as sa from sqlalchemy import orm engine = sa.create_engine('mssql://<clip>') metadata = sa.MetaData(bind=engine) Session = orm.sessionmaker(autoflush=False, autocommit=False) event_table = sa.Table('XML_INTERFAC...

Python Regex Help (httplib2 cookies)

Having the same problem as the poster of this question: http://stackoverflow.com/questions/1738227/httplib2-how-to-set-more-than-one-cookie The cookie looks like this.. PHPSESSID=8527b5532b6018aec4159d81f69765bd; path=/; expires=Fri, 19-Feb-2010 13:52:51 GMT, id=1578; expires=Mon, 22-Feb-2010 13:37:51 GMT, password=123456; expires=M...