python

Profiling of Python threads

Hello, I am trying to figure out how to measure the performance of several python threads in my application. I currently have several tasks that are executing on different threads based on user input and I would like to measure the execution time, maybe even memory consumption of each of the threads. I have tried to use cProfile (on eac...

Deciding on a blog URL scheme with regard to python performance

Hello, I'm writing a blog in Python and have come to the point where I have to decide on the URL scheme to use. It's tempting to just list the entries start to end, like: http://myblog.com/1 http://myblog.com/2 ... http://myblog.com/1568 And on the server side I would just have the blog entries in a python list. My fear though is tha...

What's wrong here? Iterating over a dictionary in Django template

I'm trying to iterate over a dictionary of model values in a Django template - I want to list the verbose_name of each model field alongside its value. Here's what I have in models.py: class Manors(models.Model): structidx = models.IntegerField(primary_key=True, verbose_name="ID") county = models.CharField(max_length=5, nu...

Many2ManyField is not saving via Modelforms

I have a Modelform: class POwner4NewModel(ModelForm): class Meta: model = ProductOwner exclude = ("o_owner","o_owner_desc","o_product_model","o_main_image","o_thumbnail","o_gallery_images","o_timestamp","o_status") This is the model's schema: class ProductOwner(models.Model): o_owner = models.ForeignKey(User, ...

Python + Komodo Edit

Hello all, I am trying to get scapy to auto complete in komodo edit with no success, has anyone successfully done this? Thanks, Python New Comer ...

Unable to access ID property from a datastore entity

Using Google App Engine SDK and Python, I'm facing an issue : I'm unable to access the ID property of a given entity properties. The only properties I can access are those defined in my class Model, plus the key property (see answer below) : class Question(db.Model): text = db.StringProperty() answers = db.StringListProperty() ...

time.localtime() - how does it work? Brief questions on how to use it too - super easy stuff!

How does time.localtime() work exactly? I can call up the "array" (tupple, I think it is called - because it is immutable?) and reference/index components of it. For example: >>> time.localtime()[0] 2010 But if I do: print time.localtime() time.struct_time(tm_year=2010, tm_mon=2, tm_mday=7, tm_hour=14, tm_min=46, tm_sec=58, tm_wday...

Is it advisable to go with Python 3.1 for a beginner?

Possible Duplicate: What version of Python should I use if Im a new to Python? Is it advisable to go with Python 3.1 for a beginner? Or are there any severe drawbacks I would have to consider? ...

Right way to return proxy model instance from a base model instance in Django ?

Say I have models: class Animal(models.Model): type = models.CharField(max_length=255) class Dog(Animal): def make_sound(self): print "Woof!" class Meta: proxy = True class Cat(Animal): def make_sound(self): print "Meow!" class Meta: proxy = True Let's say I want to do: animals =...

Python properties: Two instances of variable?

Really confused about what's going on here. I have a class defined as follows: class Profile(models.Model): user = models.OneToOneField(User) primary_phone = models.CharField(max_length=20) address = models.ForeignKey(Address) @property def primary_email(self): return self.user.email @primary_email.setter de...

Pylons: Webhelpers: missing secure_form module

I installed Pylons 0.9.7 using the go-pylons.py script. I have a line of python: from webhelpers.html.secure_form import secure_form When I try to serve my application I get the error: no module secure_form. I've tried writing import webhelpers.html.tags and other modules from webhelpers and those work. I'm wondering why I don't ha...

Independent instances of 'random'

The below code attempts to illustrate what I want. I basically want two instances of "random" that operate independently of each other. I want to seed "random" within one class without affecting "random" in another class. How can I do that? class RandomSeeded: def __init__(self, seed): import random as r1 self.random...

Matplotlib turn off antialias for text in plot?

Is there any way to turn off antialias for all text in a plot, especially the ticklabels? ...

Sizing controls for items in wx.lib.CustomTreeCtrl

Is there a trick to sizing controls for wx.lib.CUstomTreeCtrl? I've been trying to create my own custom controls (just panels with sub-controls in them) and add them as items in my CustomTreeCtrl, but when the tree renders, it's as if the panels aren't expanded to the appropriate size. I can set the panel size manually by using SetSize...

System V shared memory in Python?

How can I make use of the shmat(), shmdt(), shmctl(), shmget() calls from Python? Are they hidden somewhere in the standard library? Update0 I'm after System V bindings that can be found in the Ubuntu repositories, or Python standard libraries (now or in future releases). ...

Does the Python standard library contain a module for manipulating URIs?

I'd like to pass a URI to a constructor and get back an object on which I can call obj.type, obj.host, obj.port, etc. The "Request" object of the urllib2 module is close to what I need, but not quite it. ...

Getting PHP to run a Python script

Hi all, I am trying to run a Python program using PHP. Here's the code $command = '/usr/local/bin/python script.py file'; $temp = exec($command, $output); This works through the command line but not while running it through the browser. I am using Apache so probably it needs the right privileges? I am pretty new to Linux and have no i...

How to know all the derived classes of a parent ?

Suppose you have a base class A, and this class is reimplemented by B and C. Suppose also there's a class method A.derived() that tells you which classes are reimplementing A, hence returns [B, C], and if you later on have class D(A): pass or class D(B): pass, now A.derived() returns [B,C,D]. How would you implement the method A.derive...

perror equivalent function in python

I'm using try except block in python, while the try block fails , how to print meaningful error message. I'm looking for something like perror() in C ...

Simple example of gang scheduling of processes in Python?

I have a pool of processes that need to be executed. I would like to fully utilize the machine, so that all CPUs are executing processes. I do not want to over-subscribe the system, so what i really want is #executing_processes=#cpus at any given moment. I also need to store the stdout,stderr and return code of each completed processes....