python

Reference ID in GAE

I have a feeling the answer is simple and documented, but I'm absolutely missing it: Is there a way, using Python and webapp through Google App Engine, to pass the id field of a record to the template? I'm fairly new to the app engine, and yes, I have searched all around the Google Documentation to find this. ...

question about splitting a large file

Hey I need to split a large file in python into smaller files that contain only specific lines. How do I do this? ...

Creating square subplots (of equal height and width) in matplotlib

When I run this code from pylab import * figure() ax1 = subplot(121) plot([1, 2, 3], [1, 2, 3]) subplot(122, sharex=ax1, sharey=ax1) plot([1, 2, 3], [1, 2, 3]) draw() show() I get two subplots which are "squished" in the X-dimension. How do I get these subplots such that the height of the Y-axis equals the width of the X-axis, for bo...

Django: How do I get every table and all of that table's columns in a project?

I'm creating a set of SQL full database copy scripts using MySQL's INTO OUTFILE and LOAD DATA LOCAL INFILE. Specifically: SELECT {columns} FROM {table} INTO OUTFILE '{table}.csv' LOAD DATA LOCAL INFILE '{table}.csv' REPLACE INTO {table} {columns} Because of this, I don't need just the tables, I also need the columns for the tables. ...

Using ExecuteBatch from Python on Google Calendars API

I'm trying to figure out how to add a series of events to a non-default calendar (and remove some) as a batch, but there's no hint of how to do it in Google's frankly awful documentation. Has anyone cracked this nut or does anyone know where there is actually useful documentation on using the Google Calendar API? ...

python: access multiple values in the value portion of a key:value pair

I am trying to perform a calculation on multiple values in the value portion of a list of key:value pairs. So I have something like: [('apples', ['254', '234', '23', '33']), ('bananas', ['732', '28']), ('squash', ['3'])] I'm trying to create a list of y-values that are the averages of those integers above. What I'm trying to write i...

Suggest category for a piece of text

I've been searching for a opensource solution to suggest a category given a question or text. For example, "who is Lady Gaga?" would probably return 'Entertainment', 'Music', or 'Celebrity'. "How many strike out there are for baseball?" would give me 'Baseball', or 'Sport'. The categorization doesn't have to be perfect but should be s...

Get Mac idle time C or Python

How can i get system idle time (no keys pressed - mouse moved) in C or Python? EDIT: My program suspend a counter when idle time > 10 sec ...

Nested exceptions?

Will this work? try: try: field.value = filter(field.value, fields=self.fields, form=self, field=field) except TypeError: field.value = filter(field.value) except ValidationError, e: field.errors += e.args field.value = revert valid = False break Namely, if that first line throws a...

Python signals hosted on WSGI

I'm using the python signals library to kill a function if it runs longer than a set period of time. It works well in my tests but when hosted on the server I get the following error "signal only works in main thread" I have set the WSGI signals restriction to be off in my httpd.conf WSGIRestrictSignal Off as described http://code....

Using Python Image Library with VirtualEnv on Windows.

I'm attempting to install the PIL library in an Virtual Enviroment that I have created. Usually to install PIL I'd grab the install, however this won't allow me to choose my virtualenv only my root Python folder (C:/Python26). I tried both pip install PIL and easy_install PIP but they didn't work. I've also tried downloading the TAR, e...

additional python installed upon installing matplotlib with macports

I am having trouble installing matplotlib on mac os 10.6, so I used macports and installed all dependencies it needed, which is great, but on top of it a new python version. Now I have two python versions and that bothers me. The matplotlib is working fine on the macport python, and the rest of my stuff is with the default python. What ...

Information about computer in python

Hi, How would i go about gathering information about a system in python? Seems most of the commands are made for Unix... Are there any options in windows? Thanks, Jake. ...

How do I do a Rails style before_filter with Google App Engine?

The app is setup as a basic WSGI application. I'm just trying to call a function before the requestHandler is run. I would like something very much like the way before_filter works in Rails. Thanks. ...

using DictWriter in Python to write a subset of a dictionary's keys

I wrote a function that serializes a list of dictionaries as a CSV file using the CSV module. I sometimes want to write out to a file only a subset of each dictionary's keys however. I use the following code: def dictlist2file(dictrows, filename, fieldnames, delimiter='\t', lineterminator='\n'): out_f = open(filename, 'w') ...

Odd Behavior when Connecting to my Program

I'm using Twisted to implement a server, of sorts. When I test it, the first line it receives is always strange: Starting Server... New connection from 192.168.1.140 192.168.1.140: ÿûÿû ÿûÿû'ÿýÿûÿý\NAME Blurr 192.168.1.140: \NAME Blurr (for both inputs I sent \NAME Blurr.) This is the code that prints the input: def lineReceived(s...

HTML page to PDF in Python?

Is there a library available to convert a HTML page (text, images, layout elements etc. ) to a PDF file. I have an HTML page with figures, text and tables with numbers etc. which I want my clients to be able to download as PDF. How do I do this with Python? ...

How can I refactor this django query to not select each individual object?

Here's my view: def rsvp_list(request, id, template="rsvp/rsvp_list.html"): rsvp = RSVP.objects.get(id=id) return render_to_response(template, { 'attendees': rsvp.attendee_set.all().order_by('email__first_name'), }, context_instance=RequestContext(request)) and here's my template: {% for attendee in attendees %...

How to replace an instance in __init__() with a different object?

I am calling a constructor in ClassA and want to have the resulting object be of a different class (ClassB) if a certain condition is met. I've tried replacing the first argument to __init__() ('self' in the example below) within __init__() but it doesn't seem to do what I want. in main: import ClassA my_obj = ClassA.ClassA(500) # un...

Initialized string variable in Python?

Create a string variable that is initialized to your entire name?? Im a little lost Thanks Kim:) ...