python

Delimiting choices in ModelChoiceField

I'm new to python and to django so this question will probably be easy to solve but I can't get it to work. Basically I have a model which contains two foreign keys of User type. I'm building a form in which I want to remove one of the choices of a ModelChoiceField based on another field. I want the user to be unable to select himself in...

App Engine SDK: How do I view keys in a specific namespace using the Memcache Viewer?

I'm trying to use the Memcache Viewer in the App Engine Dev Console to view keys in a specific namespace. The obvious syntax of namespace.key is not working; I haven't been able to find documentation describing specific usage. Is this possible? ...

Using optparse to read in a list from command line options

I am calling a python script with the following command line: myscript.py --myopt="[(5.,5.),(-5.,-5.)]" The question is -- how to convert myopt to a list variable. My solution was to use optparse, treating myopt as a string, and using (options, args) = parser.parse_args() myopt = eval(options.myopt) Now, because I used eval()...

Is there a Perl alternative to YSlow?

I'd like to have a tool in Perl to gather useful statistics for page loads (eg, download time/speed, CDN information, headers, dns lookups, compressions) Does anyone know if one exists or if there's a place to learn about how to make one? ...

Set minimum column width to header width in PyQt4 QTableWidget

I'm working with the QTableWidget component in PyQt4 and I can't seem to get columns to size correctly, according to their respective header lengths. Here's what the table layout should look like (sans pipes, obviously): Index | Long_Header | Longer_Header 1 | 102402 | 100 2 | 123123 | 2 3 | 454689 | 18 The...

OOPs paradigm in Python

Here is something I've been having a doubt about. Consider the following snippet. class A(object): def check(self): super(A, self).check() print "inside a" class B(object): def check(self): print "inside b" class C(A, B): pass c = C() c.setup() Now this gives the output, inside b inside a Pass...

Vim - run ctags on current python site-packages

This is what I need - have a key that will create ctags of my python site-packages. I have this command, that will print the site-packages path: !python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" This is how I to the key mapping: map <F11> :!ctags -R -f ./tags *site-packages-path-goes-here*<CR> How...

best python lib to make the textarea safe in the web page when user submit.

i want to clean some tag like : <script> and other, so what python lib you are using to do this . thanks ...

Zooming into a Clutter CairoTexture while re-drawing.

I am using python-clutter 1.0 My question in the form of a challenge Write code to allow zooming up to a CairoTexture actor, by pressing a key, in steps such that at each the actor can be re-drawn (by cairo) so that the image remains high-res but still scales as expected, without re-sizing the actor. Think of something like Inkscape a...

Embedded Linux device tree parser in python?

I am looking to create a utility that validates Embedded (PPC or ARM) Linux *.dts (device tree source) or *.dtb (binary) files against an XML configuration file from another tool. So, I need to parse the dts or dtb files. I would really like to do this with Python. Does anyone know of a Python library or tool out there that parses dts...

Are there any implementations of slashdot style moderation in python?

Are there any implementations of slashdot style moderation in python? ...

XPath and lxml syntax

Hi everyone. I have a XML file with the structure as shown below: <x> <y/> <y/> . . </x> The number of <y> tags are arbitrary. I want to get the text of the <y> tags and for this I decided to use XPath. I have figured out the syntax, say for the first y: (Assume root as x) textFirst = root.xpath('y[1]/text()') This wor...

what's the rationale of not preserving case in configparser

Why do I have to resort to configparser.optionxform = str in order preserve case of the contents of a config file. Is it not more sane preserve by default? ...

How to add Google Analytics to reStructuredText?

Hello, I am using reStructured text to create some easy websites. So I have got a lot of *.rst files in which I want to add the Google Analytics code. But as far as I know it is not possible to add something like this?! I am using rst2html to convert the files to html. ...

Python: what's the gdata method for uploading an image with enabled OCR?

as demonstrated on this PHP code, (http://code.google.com/p/gdata-samples/source/browse/trunk/doclist/OCRDemo/ocr.php?r=194 ) where an image can be uploaded to google docs that is automatically converted to text. i'm wondering how to do this in python. there is an "upload" method, but i'm just puzzled how to enable the OCR function. ...

cannot change font to Helvetica in Matplotlib in Python on Mac OS X 10.6

I am trying to change the matplotlib font to helvetica, which I'd like to use in a PDF plot. I try the following: import matplotlib matplotlib.use('PDF') import matplotlib.pylab as plt from matplotlib import rc plt.rcParams['ps.useafm'] = True rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) plt.rcParams['pdf.fonttype'] ...

Python checking daytime

Basically, I want my script to pause between 4 and 5 AM. The only way to do this I've come up with so far is this: seconds_into_day = time.time() % (60*60*24) if 60*60*4 < seconds_into_day < 60*60*5: sleep(time_left_till_5am) Any "proper" way to do this? Aka some built-in function/lib for calculating time; rather than just using s...

how to make a delete / put request in python

i can make get or post request using urllib. how do i make delete and put requests? ...

Why do I get the following error while trying to use cPickle?

The Error: Traceback (most recent call last): File "<string>", line 244, in run_nodebug File "C:\Python26\pickleexample.py", line 13, in <module> place = cPickle.load(f) cPickle.UnpicklingError: NEWOBJ class argument has NULL tp_new My Code: import Tkinter import cPickle root = Tkinter.Tk() place = 0 root.place = Tkinter.IntVar() ro...

How can I speed up array generations in python?

I'm thinking I need to use numpy or some other library to fill these arrays fast enough but I don't know much about it. Right now this operation takes about 1 second on a quad-core Intel PC, but I need it to be as fast as possible. Any help is greatly appreciated. Thanks! import cv class TestClass: def __init__(self): w = 960 ...