python

python distutils, writing c extentions with generated source code

I have written a Python extension library in C and I am currently using distutils to build it. I also have a Python script that generates a .h file, which I would like to include with my extension. Is it possible to setup a dependency like this with distutils? Will it be able to notice when my script changes, regenerate the .h file, and...

Django form wizard uploading files

I've made a FileWizard and on the last page I'd like to have a form to upload files. Reading the documentation makes me doubt this is an easy thing to do. My initial thought is to, in the done method, grab the data and pass it into a different form, that will then accept the uploaded files before sending an email. Is this possible? Is...

drop into an interactive session to examine a failed unit test

I'd like to be able to enter an interactive session, preferably with IPython, if a unit test fails. Is there an easy way to do this? edit: by "interactive session" I mean a full Python REPL rather than a pdb shell. edit edit: As a further explanation: I'd like to be able to start an interactive session that has access to the context i...

When parsing html why do I need item.text sometimes and item.text_content() others

Still learning lxml. I discovered that sometimes I cannot get to the text of an item from a tree using item.text. If I use item.text_content() I am good to go. I am not sure I see why yet. Any hints would be appreciated Okay I am not sure exactly how to provide an example without making you handle a file: here is some code I wrote ...

Python raw literal string

str = r'c:\path\to\folder\' # my comment IDE: Eclipse, Python2.6 When the last character in the string is backslash, it seems will escape the last single quote and treat my comment as part of the string. But the raw string suppose to ignore all escape characters, right? What could be wrong? thanks. ...

how to implement thin client app with pyqt

Here is what I would like to do, and I want to know how some people with experience in this field do this: With three POST requests I get from the http server: widgets and layout and then app logic (minimal) data Or maybe it's better to combine the first two or all three. I'm thinking of using pyqt. I think I can load .ui files. I c...

python function that modifies parameters

def add(a,b): for i in range(len(a)): a[i] = a[i] + b def main(): amounts = [100,200] rate = 1 add(amounts,rate) print amounts main() The function add does not have a return. I read that changes are available to only mutable objects like list. But why did the person omits the return? Either with or without...

Python list function argument names

Is there a way to get the argument names a function takes? def foo(bar, buz): pass magical_way(foo) == ["bar", "buz"] ...

Using a variable as an object key in Django Template Tags

I have two 4 tier objects that I am passing to the django template. I am currently for looping through each tier, and going down a level if it exists. I ended up having key, key2 and key3 that represents the current location in the object while looping. I would like to reference the other object that has the same tiers using those variab...

extract specific set of lines from files

Hello, I have many large (~30 MB a piece) tab-delimited text files with variable-width lines. I want to extract the 2nd field from the nth (here, n=4) and next-to-last line (the last line is empty). I can get them separately using awk: awk 'NR==4{print $2}' filename.dat and (I don't comprehend this entirely but) awk '{y=x "\n" $2};EN...

Linking a static library into Boost Python (shared library) - Import Error

I am building a Boost Python module (.so shared library file) which depends on another external library (STXXL) While I can build and import the example Boost Python modules, I run into problems when STXXL is thrown into the mix. Specifically when running import fast_parts in python I get ImportError: ./fast_parts.so: undefined symbol...

Monitor Multiple Pylons Application

Are there any tools that I can run on my server to monitor multiple Pylons applications? I need to monitor the number of requests each application receives, how much memory each application is using, how much of the cpu is being used and other stats similar to those. I need to see the stats for each individual Pylons application. All i...

scrapy web scraper can not crawl link

Hi, I'm very new to Scrapy. Here my spider to crawl twistedweb. class TwistedWebSpider(BaseSpider): name = "twistedweb3" allowed_domains = ["twistedmatrix.com"] start_urls = [ "http://twistedmatrix.com/documents/current/web/howto/", ] rules = ( Rule(SgmlLinkExtractor(), 'parse', follow=True, ), ) def parse...

grouping strings by substring in mysql/python or mysql/.net

the data will be stored in a mysql database like this: 5911 CD $4.99 Eben, Landscapes of Patmos {w.Martin Lenniger, percussion}; 2 Choral Phantasies; Laudes. (All w.Sieglinde Ahrens, organ) 5913 CD $5.99 Turina, Sevilliana; Rafaga; Hommage a Tarrega; Sonata. Rodrigo, 3 Piezas Espanolas; En Los Trigales; Sarabande Lointaine. ...

Dealing with context classes in Python 2.4

I'm trying to use the python-daemon module. It supplies the daemon.DaemonContext class to properly daemonize a script. Although I'm primarily targeting Python 2.6+, I'd like to maintain backwards compatibility to version 2.4. Python 2.5 supports importing contexts from future, but Python 2.4 has no such facility. I figured I could just ...

how do i know what python scripts are running in windows?

as above, is there a way to find out what python scripts are running in windows? ...

Why Does Looping Beat Indexing Here?

A few years ago, someone posted on Active State Recipes for comparison purposes, three python/NumPy functions; each of these accepted the same arguments and returned the same result, a distance matrix. Two of these were taken from published sources; they are both--or they appear to me to be--idiomatic numpy code. The repetitive calcula...

Generating a set random list of integers based on a distribution

I hope I can explain this well, if I don't I'll try again. I want to generate an array of 5 random numbers that all add up to 10 but whose allocation are chosen on an interval of [0,2n/m]. I'm using numpy. The code I have so far looks like this: import numpy as np n=10 m=5 #interval that numbers are generated on randNumbers= np.rand...

Comma seperated file that I want to load into a dictionary

I have a comma seperated file, a row looks like: "ABC234234", 23 I want to load this into a dictionary, with the key being the first part i.e. "ABC234234" I have to remote the double quotes also. What's the pythonic way of doing this? ...

[Numpy] read csv into record array?

Hi, I wonder if there is a direct way to import the contents of a csv file into a record array, much in the way that R's read.table(), read.delim(), and read.csv() family imports data to R's data frame? Or is the best way to use csv.reader() and then apply something like numpy.core.records.fromrecords()? ...