python

Django development server CPU intensive - how to analyse?

Hi folks, I'm noticing that my django development server (version 1.1.1) on my local windows7 machine is using a lot of CPU (~30%, according to task manager's python.exe entry), even in idle state, i.e. no request coming in/going out. Is there an established way of analysing what might be responsible for this? Thanks! Martin ...

Does a library exist to remove passwords from PDFs programmatically?

Does a library exist that will remove "owner" passwords from PDF documents so that the text can then be programmatically extracted from them? Something like PDF Technologies' Password Recovery tool, but callable from the command line or from Python. A GUI interface is not really useful to me, since the number of documents is so large. P...

Restarting a self-updating python script

I have written a script that will keep itself up to date by downloading the latest version from a website and overwriting the running script. I am not sure what the best way to restart the script after it has been updated. Any ideas? I don't really want to have a separate update script. oh and it has to work on both linux/windows too....

Obtain MAC Address from Devices using Python

I'm looking for a way (with python) to obtain the layer II address from a device on my local network. Layer III addresses are known. The goal is to build a script that will poll a databases of IP addresses on regular intervals ensuring that the mac addresses have not changed and if they have, email alerts to myself. ...

How do I get something like repeat customers in Django

My models look something like this: class Customer(models.Model): name = models.CharField(max_length=100) class Order(models.Model): customer = models.ForeignKey(Customer) date = models.DateField() total = models.DecimalField(max_digits=5, decimal_places=2) I then have a queryset of orders: from datetime import datetime ...

Peeking in a heap in python

Hi all. What is the official way of peeking in a python heap as created by the heapq libs? Right now I have def heappeak(heap): smallest = heappop(heap) heappush(heap, smallest) return smallest which is arguably, not very nice. Can I always assume that heap[0] is the top of the heap and use that? Or would that assume too much o...

Python SOAP server / client

Hi there, I have a problem with Python and SOAP. I need to create a web service based on SOAP in Python. I read that I can use libraries like soaplib, suds and ZSI. I created a Hello World web service with soaplib, like in documentation (http://trac.optio.webfactional.com/wiki/HelloWorld). The problem is that I cannot make a client for ...

Is there any way to read the header codes without downloading the file at all?

import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() print res.status I am currently using this to get the HTTP header code of a file. However, it seems like this code DOWNLOADS the file, and then gets the code. However, some files are actually video files...and it would be ineffi...

Stuck on a loop!

I am creating an app which will be used to upload images to a specified server. I have created my GUI in Qt Designer, everything works fine I just am stuck on something that I know is simple. Cant seem to wrap my head around it. The idea is for the script to go through and see how many text fields are filed in with paths of images - fr...

Boost.Python + OpenGL segmentation faults

I have a (almost) perfectly working C++ code written with Boost.Python. It wraps a shared pointer based structure hierarchy of 3 or 4 classes, nothing terribly complex (i.e. class A has a std::vector of class B instance pointers, etc.), top level package called, say, foo. Some time ago I decided to add visualization to the project using...

Python equivalent of ruby's StringScanner?

Is there a python class equivalent to ruby's StringScanner class? I Could hack something together, but i don't want to reinvent the wheel if this already exists. ...

python paste using global egg instead of local one

I'm using Paste to run a Pylons application. Is there a way to specify in my paste config file to use the egg from the current directory (the same dir as the config file) instead of looking in global site-packages? For example, right now the config file has: [app:main] use = egg:example This definitely looks to site-packages. This ...

How can I append data to a text file with a line break using Python?

I've just been asked to come up with a script to find files with a certain filename length. I've decided to try out Python for the first time for this task as I've always wanted to learn it. I've got the script to find the files and append them to a text file but it does not write a line break for each new entry. Is there a way to do th...

Custom traversal and page templates

Using Marius Gedminas's excellent blog post, I have created a custom traverser for a folder in my site. This allows me to show: http://foo.com/folder/random_id Instead of: http://foo.com/folder/object.html?id=random_id The configuration side works great, I can catch the random_ids and search through my messages for the correct one, re...

How to loop until EOF in Python?

I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-) I have a stream (in this case, it's a StringIO object, but I'm curious about the general case as well) which stores an unknown number of records in "<length><data>...

In Python, what does getresponse() return?

import httplib conn = httplib.HTTPConnection(head) conn.request("HEAD",tail) res = conn.getresponse() I can get the res.status , which is the http status code. What other elements can I get? Why is it that when I do print res, it won't print the dictionary? I just want to see the keys that are in that dictionary... ...

How to get the true URL of a file on the web. (Python)

I notice that sometimes audio files on the internet have a "fake" URL. http://garagaeband.com/3252243 And this will 302 to the real URL: http://garageband.com/michael_jackson4.mp3 My question is...when supplied with the fake URL, how can you get the REAL URL from headers? Currently, this is my code for reading the headers of a f...

What conditions cause Tokyo Cabinet to block

I'm using Tokyo Cabinet with the tc module in python. I store my data in the TDB format. I expected the table to block only for the duration of a write. Unfortunately, I see that when the file is open with in the "writer mode", other processes cannot read from it. Is that a standard behaviour, wrappers problem, or am I doing something wr...

Python LEPL LineAwareConfiguration trouble

Hello. I'm new to using python's LEPL, and it looks great. However, I'm trying to use the LineAwareConfiguration to easily handle a grammar in which whitespace matters, and I'm running into some serious issues. Namely, this code works: from lepl import * broken = Token(r'.') parser = broken[:].string_parser() While this code yields a ...

BeautifulSoup - easy way to to obtain HTML-free contents.

I'm using this code to find all interesting links in a page: soup.findAll('a', href=re.compile('^notizia.php\?idn=\d+')) And it does its job pretty well. Unfortunately inside that a tag there are a lot of nested tags, like font, b and different things... I'd like to get just the text content, without any other html tag. Example of l...