python

Programming a Logitech G15 using python

I'd like to be able to write apps for my G15 keyboard using python. There seems to be a few people out there who have done it in the past, but I'm not sure what packages I need to install or where I should start. Does anyone have any experience with this? ...

How to integrate pep8.py in Eclipse?

A little background: PEP 8 is the Style Guide for Python Code. It contains the conventions all python programmers should follow. pep8.py is a (very useful) script that checks the code formating of a given python script, according to PEP 8. Eclipse is a great IDE. With the Pydev extension, it that can be used to develop Python I run p...

Need help on selecting items in simple database in python.

I'm trying to write a circuit schematic drawing tool in Python. I'm creating a simple database based on dictionaries which holds all the components and their properties. I'm also trying to create a simple query language where you can select, for example, all resistors with value>100ohms or footprint='0402' So far, I can select thing...

Ignoring XML errors in Python

I am using XML minidom (xml.dom.minidom) in Python, but any error in the XML will kill the parser. Is it possible to ignore them, like a browser for example? I am trying to write a browser in Python, but it just throws an exception if the tags aren't fully compatible. ...

How do you get Python to write down the code of a function it has in memory?

When I pass the options in the program (a computational biology experiment) I usually pass them through a .py file. So I have this .py file that reads like: starting_length=9 starting_cell_size=1000 LengthofExperiments=5000000 Then I execute the file and get the data. Since the program is all on my machine and no one else has access t...

Reading and running a mathematical expression in Python

Using Python, how would I go about reading in (be from a string, file or url) a mathematical expression (1 + 1 is a good start) and executing it? Aside from grabbing a string, file or url I have no idea of where to start with this. ...

What does * mean in Python?

Does * have a special meaning in Python as it does in C? I saw a function like this in the Python Cookbook: def get(self, *a, **kw) Would you please explain it to me or point out where I can find an answer (Google interprets the * as wild card character and thus I cannot find a satisfactory answer). Thank you very much. ...

Resize image in Python without losing EXIF data

I need to resize jpg images with Python without losing the original image's EXIF data (metadata about date taken, camera model etc.). All google searches about python and images point to the PIL library which I'm currently using, but doesn't seem to be able to retain the metadata. The code I have so far (using PIL) is this: img = Image....

Define css class in django Forms

Assume I have a form class SampleClass(forms.Form): name = forms.CharField(max_length=30) age = forms.IntegerField() django_hacker = forms.BooleanField(required=False) Is there a way for me to define css classes on each field such that I can then use jQuery based on class in my rendered page? I was hoping not to have to m...

ForeignKey form restrictions in Django

I'm using Django to write a blog app, and I'm trying to implement a hierarchical category structure. Each category has a "parent" ForeignKey pointing back to the same Category model. I want to allow admins to add categories, and I want the interface to allow them to select a category's parent category. However, I want to avoid I'm-my-...

How to limit rate of requests to web services in Python?

I'm working on a Python library that interfaces with a web service API. Like many web services I've encountered, this one requests limiting the rate of requests. I would like to provide an optional parameter, limit, to the class instantiation that, if provided, will hold outgoing requests until the number of seconds specified passes. I ...

Naming Python loggers

In Django, I've got loggers all over the place, currently with hard-coded names. For module-level logging (i.e., in a module of view functions) I have the urge to do this. log= logging.getLogger( __name__ ) For class-level logging (i.e., in a class __init__ method) I have the urge to do this. self.log= logging.getLogger( "%s.%s" % (...

Regex that only matches text that's not part of HTML markup? (python)

How can I make a pattern match so long as it's not inside of an HTML tag? Here's my attempt below. Anyone have a better/different approach? import re inputstr = 'mary had a <b class="foo"> little loomb</b>' rx = re.compile('[aob]') repl = 'x' outputstr = '' i = 0 for astr in re.compile(r'(<[^>]*>)').split(inputstr): i = 1 - i ...

Scaling the y-axis with matplotlib in python

Does anybody know how to scale the y-axis with matplotlib? I don't want to change the y-limit, I just want to extend the physical space. ^ ^ | | | | +----> | Before +----> After Thanks! ...

How to store a dictionary on a Django Model?

I need to store some data on a Django model. These data are not equal to all instances of the model. At first I thought on subclassing the model, but I'm trying to keep the application flexible; if I use subclasses, I'll need to create a whole class each time i need a new kind of object, and that's no good. I'll also end up with a lot o...

How do you uninstall a python package that was installed using distutils?

Can you simply delete the directory from your python installation, or are there any lingering files that you must delete? ...

Help--Function Pointers in Python

My idea of program: I have a dictionary: options = { 'string' : select_fun(function pointer), 'float' : select_fun(function pointer), 'double' : select_fun(function pointer) } whatever type comes single function select_fun(function pointer) gets called. Inside select_fun(function pointer),I will have diff functions for float, double ...

Caching result of setUp() using Python unittest

I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers = Trailers(res = "720", verbose = True) def test_has_trailers(self): self.failUnless(len(self.all_trailers) > 1) # ..more tests.. This works fine, but the Trailers() call t...

How to determine the variable type in Python

I want to see the type of a variabe whether it is unsigned 32 bit,signed 16 bit etc. How to view... ...

How to sort a list of objects in Python, based on an attribute of the objects?

I've got a list of Python objects that I'd like to sort by an attribute of the objects themselves. The list looks like: >>> ut [<Tag: 128>, <Tag: 2008>, <Tag: <>, <Tag: actionscript>, <Tag: addresses>, <Tag: aes>, <Tag: ajax> ...] Each object has a count: >>> ut[1].count 1L I need to sort the list by number of counts descending. ...