python

Explaining persistent data structures in simple terms

I'm working on a library for Python that implements some persistent data structures (mainly as a learning exercise). However, I'm beginning to learn that explaining persistent data structures to people unfamiliar with them can be difficult. Can someone help me think of an easy (or at least the least complicated) way to describe persist...

python: Change the scripts working directory to the script's own directory

Hi, I run a python shell from crontab every minute: * * * * * /home/udi/foo/bar.py /home/udi/foo has some necessary subdirectories, like /home/udi/foo/log and /home/udi/foo/config, which /home/udi/foo/bar.py refers to. The problem is that crontab runs the script from a different working directory, so trying to open ./log/bar.log fai...

Generate and parse Python code from C# application.

I need to generate Python code to be more specific IronPyton. I also need to be able to parse the code and load it into AST. I just started looking at some tools. I played with "Oslo" and made decision that it's not the right tool for me. I just looked very briefly at Coco/R and it looks promising. Does any one used Coco/R? If you d...

How do I run a sub-process, display its output in a GUI and allow it to be terminated?

I have been trying to write an application that runs subprocesses and (among other things) displays their output in a GUI and allows the user to click a button to cancel them. I start the processes like this: queue = Queue.Queue(500) process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) iothr...

Can we use a python variable to hold an entire file ?

Provided that we know that all the file will be loaded in memory and we can afford it, what are the drawbacks (if any) or limitations (if any) of loading an entire file (possibly a binary file) in a python variable. If this is technically possible, should this be avoided, and why ? Regarding file size concerns, to what maximum size this...

Getting text values from XML in Python

from xml.dom.minidom import parseString dom = parseString(data) data = dom.getElementsByTagName('data') the 'data' variable returns as an element object but I cant for the life of me see in the documentation to grab the text value of the element. For example: <something><data>I WANT THIS</data></something> Anyone have any ideas? ...

Compiling Python

How can I compile and run a python file (*.py extension)? ...

python help needed

import os import sys, urllib2, urllib import re import time from threading import Thread class testit(Thread): def __init__ (self): Thread.__init__(self) def run(self): url = 'http://games.espnstar.asia/the-greatest-odi/post_brackets.php' data = urllib.urlencode([('id',"btn_13_9_13"), ('matchNo',"13")]) ...

PyQt4 - Image Watermark

I'm trying to open a PNG image and write some text to it (a watermark) via QImage and QPainter. The code works 100% on Linux but when I run it on Windows XP (haven't tested with any other versions of Windows) the text is never written to the image. I have the code in a try/except block, but no errors are returned. image = QtGui.QImage('...

Invalid syntax error

import os import sys, urllib2, urllib import re import time from threading import Thread class testit(Thread): def _init_ (self): Thread.__init__(self) def run(self): url = 'http://games.espnstar.asia/the-greatest-odi/post_brackets.php' data = urllib.urlencode([('id',"btn_13_9_13"), ('matchNo',"1...

Thread error in Python & PyQt

I noticed that when the function setModel is executed in parallel thread (I tried threading.Timer or threading.thread), I get this: QObject: Cannot create children for a parent that is in a different thread. (Parent is QHeaderView(0x1c93ed0), parent's thread is QThread(0xb179c0), current thread is QThread(0x23dce38) QObject::startTimer:...

Socket in use error when reusing sockets

I am writing an XMLRPC client in c++ that is intended to talk to a python XMLRPC server. Unfortunately, at this time, the python XMLRPC server is only capable of fielding one request on a connection, then it shuts down, I discovered this thanks to mhawke's response to my previous query about a related subject Because of this, I hav...

Python: bind child class at run time

Hi, Can anyone tell me how to bind to specific child class at run time in the following code? I want mCar instance in the following example redirect to class Truck or Compact according to command line options? class Car(object): pass class Truck(Car): pass class Compact(Car): pass and a instance of Car mCar = Car() ...

Python memory leaks

I have a long-running script which, if let to run long enough, will consume all the memory on my system. Without going into details about the script, I have two questions: Are there any "Best Practices" to follow, which will help prevent leaks from occurring? What techniques are there to debug memory leaks in Python? ...

Retrieving values from 2 different tables with Django's QuerySet

For the following models: class Topping(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name = models.CharField(max_length=100) toppings = models.ManyToManyField(Toppping) My data looks like the following: Pizza and Topping tables joined: ID NAME TOPPINGS --------------------...

manage.py syncdb doesn't add tables for some models

My second not-so-adept question of the day: I have a django project with four installed apps. When I run manage.py syndb, it only creates tables for two of them. To my knowledge, there are no problems in any of my models files, and all the apps are specified in INSTALLED_APPS in my settings file. Manage.py syndb just seems to ignore two ...

Matplotlib Legend for Scatter with custom colours

I'm a bit of newbie at this and am trying to create a scatter chart with custom bubble sizes and colours. The chart displays fine but how do I get a legend saying what the colours refer to. This is as far as I've got: inc = [] out = [] bal = [] col = [] fig=Figure() ax=fig.add_subplot(111) inc = (30000,20000,70000) out = (80000,3000...

Getting Started with Tornado

After installing the necessary packages through apt (python 2.5, simplejson etc) I get an error when I try to run the demos. : Request instance has no attribute 'responseHeaders' /usr/lib/python2.5/site-packages/tornado/web.py, line 404 in flush 402 for k,v in self._generate_headers(): 403 if isinstance(v, list): 404 se...

Primer on writing documentation with Sphinx?

I followed a tutorial that showed only how to build it, I have it up and running on my web host but I'm a bit confused on how I should be creating and writing documentation. So far I've made a small little edit to the index.rst file and made a new reference to a page, then it obviously complains that it's an "undefined label: foobarz "....

Problem with building Boost Graph Library Python bindings under Leopard

I've inherited some Python code which is importing boost.graph and I'm having an issue setting up the following under Mac OS X Leopard (I believe this is what I need to install to get it working): http://osl.iu.edu/~dgregor/bgl-python/ According to the readme I need to build with bjam, but I see the following error: [matt@imac ~/Downl...