python

A simple freeze behavior decorator

Hi, I'm trying to write a freeze decorator for Python. The idea is as follows : (In response to the two comments) I might be wrong but I think there is two main use of test case. One is the test-driven development : Ideally , developers are writing case before writing the code. It usually helps defining the architecture because t...

Equivalent for LinkedHashMap in Python

LinkedHashMap is the Java implementation of a Hashtable like data structure (dict in Python) with predictable iteration order. That means that during a traversal over all keys, they are ordered by insertion. This is done by an additional linked list maintaining the insertion order. Is there an equivalent to that in Python? ...

Python Hash Functions

What is a good way of hashing a hierarchy (similar to a file structure) in python? I could convert the whole hierarchy into a dotted string and then hash that, but is there a better (or more efficient) way of doing this without going back and forth all the time? An example of a structure I might want to hash is: a -> b1 -> c -> 1 -> d...

Python file modes detail

In python following statements do not work: f = open("ftmp", "rw") print >> f, "python" I get the error: Traceback (most recent call last): File "<stdin>", line 1, in <module> IOError: [Errno 9] Bad file descriptor But with the following code it works: g = open("ftmp", "r+") print >> g, "python" Looks like I need to revise the...

Is there any preferable way to get user/group information from an Active Directory domain in Python?

For a Django application that I'm working on, I wanted to allow group membership to be determined by Active Directory group. After a while of digging through the pywin32 documentation, I came up with this: >>> import win32net >>> win32net.NetUserGetGroups('domain_name.com', 'username') [(u'Domain Users', 7), ...] I spent a while goog...

splitting a ManyToManyField over multiple form fields in a ModelForm

So I have a model with a ManyToManyField called tournaments. I have a ModelForm with two tournament fields: pay_tourns = forms.ModelMultipleChoiceField( queryset=Tourn.objects.all().active().pay_tourns(), widget=forms.CheckboxSelectMultiple()) rep_tourns = forms.ModelMultipleChoiceField( ...

How do I create a unique value for each key using dict.fromkeys?

First, I'm new to Python, so I apologize if I've overlooked something, but I would like to use dict.fromkeys (or something similar) to create a dictionary of lists, the keys of which are provided in another list. I'm performing some timing tests and I'd like for the key to be the input variable and the list to contain the times for the r...

Python process management

Is there any way python is natively, or through some code available online (preferably under the GPL), capable of doing process management. The goal is similar to the functionality of ps, but preferably in arrays, lists, and/or dicts. ...

python postgres cursor timestamp issue

I am somewhat new to transactional databases and have come across an issue I am trying to understand. I have created a simple demonstration where a database connection is stored inside each of the 5 threads created by cherrypy. I have a method that displays a table of timestamps stored in the database and a button to add a new record...

Sending Rich Text Format email using Outlook 2003

I am trying to send a Rich Text Format email message using Outlook 2003. The following code results the RTF HTML source code to be dumped into the mail message body. What should I do in order to fix that, and make Outlook display the formatted data and not the source HTML ? import win32com.client RTFTEMPLATE = """<!DOCTYPE HTML PUBLIC...

How to configure IPython to use gvim on Windows?

This really looks like something I should be able to find on Google, but for some reason I can't make heads or tails of it. There's the EDITOR environment variable, the ipy_user_conf.py file, the ipythonrc file, some weird thing about running gvim in server mode and a bunch of other stuff I can't wrap my head around (probably because of ...

Why is wx.SingleChoiceDialog not subclassing properly

I'm trying to subclass the wxpython SingleChoiceDialog class. I have a TableChoiceDialog class that inherits from SingleChoiceDialog adding generic functionality, and I have 2 sub classes for that add more refined functionality. Basically I'm O.O.P'ing In my TableChoiceDialog class I have a line which calls the superclass's __init__, ...

python regular expression for retweets

i'm working on a regex that will extract retweet keywords and user names from tweets. here's an example, with a rather terrible regex to do the job: tweet='foobar RT@one, @two: @three barfoo' m=re.search(r'(RT|retweet|from|via)\b\W*@(\w+)\b\W*@(\w+)\b\W*@(\w+)\b\W*',tweet) m.groups() ('RT', 'one', 'two', 'three') what i'd like is to c...

Can I get rows from SQLAlchemy that are plain arrays, rather than dictionaries?

I'm trying to optimize some Python code. The profiler tells me that SQLAlchemy's _get_col() is what's killing performance. The code looks something like this: lots_of_rows = get_lots_of_rows() for row in lots_of_rows: if row.x == row.y: print row.z I was about to go through the code and make it more like this... lots_of_r...

Why did Python 2.6 add a global next() function?

I noticed that Python2.6 added a next() to it's list of global functions. next(iterator[, default])¶ Retrieve the next item from the iterator by calling its next() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised. What was the motivation for adding this? What can...

Implementation: How to retrieve and send emails for different Gmail accounts?

Hello all, I need advice and how to got about setting up a simple service for my users. I would like to add a new feature where users can send and receive emails from their gmail account. I have seen this done several times and I know its possible. There use to be a project for "Libgmailer" at sourceforge but I think it was abandoned. ...

python time + timedelta equivalent

I'm trying to do something like this: time() + timedelta(hours=1) however, python has no allowance for it, apparently for good reason http://bugs.python.org/issue1487389 Does anyone have a simple work around? Related Python - easy way to add N seconds to a datetime.time? ...

Python lib to Read a Flash swf Format File

I'm interested in using Python to hack on the data in Flash swf files. There is good documentation available on the format of swf files, and I am considering writing my own Python lib to parse that data out using the standard Python struct lib. Does anybody know of a Python project that already does this? I would also be interested in...

PyWinAuto still useful?

I've been playing with PyWinAuto today and having fun automating all sorts GUI tests. I was wondering if it is still state of the art or if there might be something else (also free) which does windows rich client automation better. ...

Communicating with a running python daemon

I wrote a small Python application that runs as a daemon. It utilizes threading and queues. I'm looking for general approaches to altering this application so that I can communicate with it while it's running. Mostly I'd like to be able to monitor its health. In a nutshell, I'd like to be able to do something like this: python applic...