python

PyQt subclassing

The usual way to use Qt widgets from Python seems to be to subclass them. Qt widget classes have a great many methods, so inevitably I'm going to end up adding a method to the subclass, with the same name as one inherited from the Qt widget. In Python, all methods are virtual, so what I'm concerned about is that some Qt code might end u...

how to create windows 7 jump lists via python/pyqt?

i have a pyqt project which i'm interested in using to play around with the new windows 7 jump list feature. after a bunch of searching, i have not found any specific examples of anyone creating jumplists via python. has anyone here found an easy way to hook into this? does mark hammond's pywin32 module have an appropriate wrapper? t...

How to share variables across scripts in python?

The following does not work one.py import shared shared.value = 'Hello' raw_input('A cheap way to keep process alive..') two.py import shared print shared.value run on two command lines as: >>python one.py >>python two.py (the second one gets an attribute error, rightly so). Is there a way to accomplish this, that is, share a ...

python modify __metaclass__ for whole program

EDIT: Note that this is a REALLY BAD idea to do in production code. This was just an interesting thing for me. Don't do this at home! Is it possible to modify __metaclass__ variable for whole program (interpreter) in Python? This simple example is working: class ChattyType(type): def __init__(cls, name, bases, dct): print...

How can I programmatically obtain the max_length of a Django model field?

Say I have a Django class something like this: class Person(models.Model): name = models.CharField(max_length=50) # ... How can I programatically obtain the max_length value for the name field? ...

Python 3: Best string compression method to minimize the size of a sqlite3 db

I recently created a script that parses several web proxy logs into a tidy sqlite3 db file that is working great for me... with one snag. the file size. I have been pressed to use this format (a sqlite3 db) and python handles it natively like a champ, so my question is this... what is the best form of string compression that I can use...

pythonic way to aggregate arrays (numpy or not)

Hi, I would like to make a nice function to aggregate data among an array (it's a numpy record array, but it does not change anything) you have an array of data that you want to aggregate among one axis: for example an array of dtype=[(name, (np.str_,8), (job, (np.str_,8), (income, np.uint32)] and you want to have the mean income per j...

Delaunay tessellation in Python?

I need to find the Delaunay tessellation of a polygon in Python, and the only libraries I could find (Delny, scikits) triangulate point clouds, not polygons. Any suggestions? ...

Ranking Elements of multiple Lists by their count in Python

I want to rank multiple lists according to their elements how often they appear in each list. Example: list1 = 1,2,3,4 list2 = 4,5,6,7 list3 = 4,1,8,9 result = 4,1,2,3,4,5,6,7,8 (4 is counted three times, 1 two times and the rest once) I've tried the following but i need something more intelligent and something i can do with any ammou...

How to run installed python script?

I used distutils to install my python package, with this setup.py : import distutils.core args = { 'name' : 'plugh', 'version' : '1.0', 'scripts' : [ "scripts/plugh" ], 'packages': [ "plugh" ], } d = distutils.core.setup( **args ) On linux/mac, it works as expected: % plugh hel...

Read datetime back from sqlite as a datetime in Python

I'm using the sqlite3 module in Python 2.6.4 to store a datetime in a SQLite database. Inserting it is very easy, because sqlite automatically converts the date to a string. The problem is, when reading it it comes back as a string, but I need to reconstruct the original datetime object. How do I do this? ...

reusable application for django site wide announcements that displays a message only once per user.

I want to show various messages to registered users only once in my django application. I found django-announcements which seemed to do what I want - but I found in testing it marks messages as read by using a session variable, which disappears if the user logs out. This means a message is shown again to a user if they dismiss it when l...

Good way to pass variables for common elements to Mako templates?

I'm using Mako's inheritance features to factor out common page elements, like a header and footer, into a "base.mako" template. Page-specific controllers use their own templates, which inherit base.mako. base.mako needs a set of variables -- for example, the name of the logged-on user goes in the header for all pages. However, it's ...

TypeError: ListControl, must set a sequence (python error)

I am using Python Mechanize to open a website, fill out a form, and submit that form. It's actually pretty simple. It works until I come across radio buttons and "select" input boxes. br.open(url) br.select_form(name="postmsg") br.form['subject'] = "Is this good for the holidays? " br.form['message'] = "I'm new to technology." br.form['...

How can I use pywin32 with a virtualenv without having to include the host environment's site-packages folder?

I'm working with PyInstaller under Python 2.6, which is only partially supported due to the mess MS have created with their manifest nonense which now affects Python since it is now MSVC8 compiled. The problem is that the manifest embedding support relies on the pywin32 extensions in order to build which is a pain because without includ...

why Ghost Process appears after kill -9

Hi, In my Python script, I first launch a subprocess by subprocess.Popen(). Then later on, I want to kill that subprocess by kill -9 Pid. What I found is that after the kill is executed, the subprocess is "stopped" because the GUI window of that process disappeared immediately. But when I perform a "ps aux" right after the kill, the sa...

python locale strange error. what's going on here exactly ?

Hello. So today I upgraded to bazaar 2.0.2, and I started receiving this message (I'm on snow leopard, btw): bzr: warning: unknown locale: UTF-8 Could not determine what text encoding to use. This error usually means your Python interpreter doesn't support the locale set by $LANG (en_US.UTF-8) Continuing with ascii encoding. ...

How to submit a form with more than 1 submit button. Sending a POST to a website. (Python)

I am creating a script using Python Mechanize that can login to a website and submit a form. However, this form has 3 submit buttons (Preview, Post, and Cancel). I'm used to only one button... This is the form: <TextControl(subject=Is this good for the holidays? Anyone know about the new tech?)> <IgnoreControl(threads=<None>)> <Tex...

ask a Python list operation

I frequently write code like: lines = open('wordprob.txt','r').readlines() words = open('StdWord.txt','r').readlines() i = 0 for line in lines: v = [eval(s) for s in line.split()] if v[0] > v[1]: print words[i].strip(), i += 1 Is it possible to avoid use variable i and make the program shorter? Thanks. ...

how to find the owner of a file or directory in python

I need a function or method in Python to find the owner of a file or directory? the function should be link find_owner("/home/somedir/somefile") owner3 ...