python

distutils setup.py and %post %postun

Hi, I am newbie. I am buidling rpm package for my own app and decided to use distutils to do achieve it. I managed to create some substitue of %post by using advice from this website, which i really am thankfull for, but i am having problems with %postun. Let me describe what i have done. In setup.py i run command that creates symbolic ...

python database / sql programming - where to start

What is the best way to use an embedded database, say sqlite in Python: Should be small footprint. I'm only needing few thousands records per table. And just a handful of tables per database. If it's one provided by Python default installation, then great. Must be open-source, available on Windows and Linus. Better if SQL is not wri...

Why does the Python gettext module require a compilation step (.po -> .mo) ?

I don't see that the compilation step is adding any value. ...

How do I regex match with grouping with unknown number of groups

I want to do a regex match (in Python) on the output log of a program. The log contains some lines that look like this: ... VALUE 100 234 568 9233 119 ... VALUE 101 124 9223 4329 1559 ... I would like to capture the list of numbers that occurs after the first incidence of the line that starts with VALUE. i.e., I want it to return ('...

Does python logging.handlers.RotatingFileHandler allow creation of a group writable log file?

I'm using the standard python (2.5.2) logging module, specifically the RotatingFileHandler, on a linux system. My application supports both a command-line interface and a web-service interface. I would like to have both write to the same log file. However, when the log file gets rotated, the new file has 644 permissions and is owned b...

Python: How do I convert a NonType variable to a String?

I have the following function: >>> def rule(x): ... rule = bin(x)[2:].zfill(8) ... rule = str(rule) ... print rule I am trying to convert rule into a string, but when I run the following command, here is what I get: >>> type(rule(20)) 00010100 <type 'NoneType'> What is a NoneType variable and how can I convert this va...

Is there an Rake equivalent in Python?

Rake is a software build tool written in Ruby (like ant or make), and so all its files are written in this language. Does something like this exist in Python? ...

Python urllib, minidom and parsing international characters

When I try to retrive information from google weather api with the followign url, http://www.google.com/ig/api?weather=Munich,Germany&amp;hl=de and then try to parse it with minidom, I get error that the document is not well formed. I use following code sock = urllib.urlopen(url) # above mentioned url doc = minidom.parse(sock) I t...

Create an executable process without using shell on Python 2.5 and below

Just what the title says: The subprocess module cannot be used as this should work on 2.4 and 2.5 Shell process should not be spawned to pass arguments. To explain (2), consider the following code: >>> x=os.system('foo arg') sh: foo: not found >>> x=os.popen('foo arg') sh: foo: not found >>> As you can see os.system and os.popen r...

Thread local storage in Python

How do I use thread local storage in Python? Related What is “thread local storage” in Python, and why do I need it? - This thread appears to be focused more on when variables are shared. Efficient way to determine whether a particular function is on the stack in Python - Alex Martelli gives a nice solution ...

Nice Python Decorators

How do I nicely write a decorator? In particular issues include: compatibility with other decorators, preserving of signatures, ect. I would like to avoid dependency on the decorator module if possible, but if there were sufficient advantages, then I would consider it. Related Preserving signatures of decorated functions - much more...

Get file creation time with Python on linux

os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime "change time" on POSIX. is there any function that return the creation time of a file using python and under Linux? ...

Help with Python/Qt4 and QTableWidget column click

Hi folks, I'm trying to learn PyQt4 and GUI design with QtDesigner. I've got my basic GUI designed, and I now want to capture when the user clicks on a column header. My thought is that I need to override QTableWidget, but I don't know how to attach to the signal. Here's my class so far: class MyTableWidget(QtGui.QTableWidget): ...

Python: NoneType errors.Do they look familiar.

I've been looking for the NoneType for half a day. I've put 'print' and dir() all through the generation of the Object represented by t2. I've looked at the data structure after the crash using 'post mortem' and nowhere can I find a NoneType. I was wondering if perhaps it's one of those errors that are initiated by some other part of the...

numpy array slice using None

This had me scratching my head for a while. I was unintentionally slicing an array with None and getting something other than an error (I expected an error). Instead, it returns an array with an extra dimension. >>> import numpy >>> a = numpy.arange(4).reshape(2,2) >>> a array([[0, 1], [2, 3]]) >>> a[None] array([[[0, 1], ...

send an arbitrary number of inputs from python to a .exe

p = subprocess.Popen(args = "myprog.exe" + " " + str(input1) + " " + str(input2) + " " + str(input3) + " " + strpoints, stdout = subprocess.PIPE) in the code above, input1, input2, and input3 are all integers that get converted to strings. the variable...

Keyboard Interrupts with python's multiprocessing Pool

How can I handle KeyboardInterrupt events with python's multiprocessing Pools? Here is a simple example: from multiprocessing import Pool from time import sleep from sys import exit def slowly_square(i): sleep(1) return i*i def go(): pool = Pool(8) try: results = pool.map(slowly_square, range(40)) except Ke...

How can you profile a parallelized Python script?

Suppose I have a python script called my_parallel_script.py that involves using multiprocessing to parallelize several things and I run it with the following command: python -m cProfile my_parallel_script.py This generates profiling output for the parent process only. Calls made in child processes are not recorded at all. Is it possib...

Improving a Python Script that Updates Apache DocumentRoot

I'm tired of going through all the steps it takes (for me) to change the DocumentRoot in Apache. I'm trying to facilitate the process with the following Python script... #!/usr/bin/python import sys, re if len(sys.argv) == 2: f = open('/tmp/apachecdr', 'w') f.write(open('/etc/apache2/httpd.conf').read()) f = open('/tmp/apachecdr',...

Track process status with Python

hello, I want to start a number of subprocesses in my Python script and then track when they complete or crash. subprocess.Popen.poll() seems to return None when the process is still running, 0 on success, and non-zero on failure. Can that be expected on all OS's? Unfortunately the standard library documentation is lacking for these me...