python

Can I restrict nose coverage output to directory (rather than package)?

My SUT looks like: foo.py bar.py tests/__init__.py [empty] tests/foo_tests.py tests/bar_tests.py tests/integration/__init__.py [empty] tests/integration/foo_tests.py tests/integration/bar_tests.py When I run nosetests --with-coverage, I get details for all sorts of modules that I'd rather ignore. But I can't use the --cover-package=P...

How Big can a Python Array Get?

In Python, how big can an array/list get? I need an array about 12000 elements large... is that okay? - will I still be able to run array/list methods such as sorting, etc? Thanks so much, Ed ...

Getting local dictionary for function scope only in Python

I keep ending up at this situation where I want to use a dictionary very much like the one 'locals' gives back, but that only contains the variables in the limited scope of the function. Is there a way to do this in python? A bit more about why I want to do this: I'm playing with Django and when I go to give my templates context, I am ...

Running django on OSX

I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache. I'm running OSX 10.5 and have the standard apache (which refuses to run ...

referenced before assignment error in python

In Python I'm getting the following error: UnboundLocalError: local variable 'total' referenced before assignment At the start of the file (before the function where the error comes from), I declare 'total' using the global keyword. Then, in the body of the program, before the function that uses 'total' is called, I assign it to 0. I'...

Why can't I pass a direct reference to a dictionary value to a function?

Earlier today I asked a question about passing dictionary values to a function. While I understand now how to accomplish what I was trying to accomplish the why question (which was not asked) was never answered. So my follow up is why can't I def myFunction(newDict['bubba']): some code to process the parameter Is it simply beca...

How do I upload a files to google app engine app when field name is not known

I have tried a few options, none of which seem to work (if I have a simple multipart form with a named field, it works well, but when I don't know the name I can't just grab all files in the request...). I have looked at http://stackoverflow.com/questions/81451/upload-files-in-google-app-engine and it doesn't seem suitable (or to actua...

Python try-else

I am just now learning Python, and I came across an interesting construct. In Python, the try block has an optional else block. Other than providing a new scope after the try exits normally, what does the else block do for you? Or is that just it? ...

Please introduce a multi-processing library in Perl or Ruby

In python we can use multiprocessing modules. If there is a similar library in Perl and Ruby, would you teach it? I would appreciate it if you can include a brief sample. ...

Auto-populating created_by field with Django admin site

I want to use the Django admin interface for a very simple web application but I can't get around a problem that should not be that hard to resolve .. Consider the following: class Contact(models.Model): name = models.CharField(max_length=250, blank=False) created_by = models.ForeignKey(User, blank=False) I can't find a way t...

Subclassing ctypes - Python

This is some code I found on the internet. I'm not sure how it is meant to be used. I simply filled members with the enum keys/values and it works, but I'm curious what this metaclass is all about. I am assuming it has something to do with ctypes, but I can't find much information on subclassing ctypes. I know EnumerationType isn't doing...

Changing LD_LIBRARY_PATH at runtime for ctypes

How do you update this environment variable at runtime so that ctypes can load a library wherever? I've tried the following and neither seem to work. from ctypes import * os.environ['LD_LIBRARY_PATH'] = "/home/starlon/Projects/pyCFA635/lib" os.putenv('LD_LIBRARY_PATH', "/home/starlon/Projects/pyCFA635/lib") lib = CDLL("libevaluator....

launch a process off a mysql row insert

I need to launch a server side process off a mysql row insert. I'd appreciate some feedback/suggestions. So far I can think of three options: 1st (least attractive): My preliminary understanding is that I can write a kind of "custom trigger" in C that could fire off a row insert. In addition to having to renew my C skills this would r...

what are the applications of the python reload function?

I have been wondering about the reload() function in python, which seems like it can lead to problems if used without care. Why would you want to reload a module, rather than just stop/start python again? I imagine one application might be to test changes to a module interactively. ...

How do I represent many to many relation in the form of Google App Engine?

class Entry(db.Model): ... class Tag(db.Model): ... class EntryTag(db.Model): entry = db.ReferenceProperty(Entry, required=True, collection_name='tag_set') tag = db.ReferenceProperty(Tag, required=True, collection_name='entry_set') The template should be {{form.as_table}} The question is how to make a form to create ...

tokenize module

Hello, Please help There are many tokens in module tokenize like STRING,BACKQUOTE,AMPEREQUAL etc. >>> import cStringIO >>> import tokenize >>> source = "{'test':'123','hehe':['hooray',0x10]}" >>> src = cStringIO.StringIO(source).readline >>> src = tokenize.generate_tokens(src) >>> src <generator object at 0x00BFBEE0> >>> src.next(...

PyAMF / Django - Flex class mapping errors

Hey there, I'm using PyAmf to communicate with a Flex app. But I keep getting errors. My model: from django.contrib.auth.models import User class Talent(User): street = models.CharField(max_length=100) street_nr = models.CharField(max_length=100) postal_code = models.PositiveIntegerField() city = models.CharField(max_...

arrays in python

Hi I just started work on my first python script What's the best way to create 2 D arrays in python ? What I want is want is to store values like this : X , Y , Z so that I access date like X[2],Y[2],Z[2] or X[n]Y[n],Z[n] where n is varialble I don't know in the beginning how big n would be so I would to append values at the end ...

Does python have a call_user_func() like PHP?

Does python have a function like call_user_func() in PHP? PHP Version: call_user_func(array($object,$methodName),$parameters) How do I achieve the above in Python? ...

Infinite recursion trying to check all elements of a TreeCtrl

I have a TreeCtrl in which more than one Item can be assigned the same object as PyData. When the object is updated, I want to update all of the items in the tree which have that object as their PyData. I thought the following code would solve the problem quite neatly, but for some reason the logical test (current != self.GetFirstVisibl...