python

Python: "Indentation Error: unindent does not match any outer indentation level"

I just can't figure out what's wrong with this... #!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configuration Vars conf = { "start_energy": ...

Accessing a matrix element by matrix[(a, b), c] instead of matrix[a, b, c].

I want to achieve the following: Have a AxBxC matrix (where A,B,C are integers). Access that matrix not as matrix[a, b, c] but as matrix[(a, b), c], this is, I have two variables, var1 = (x, y) and var2 = z and want access my matrix as matrix[var1, var2]. How can this be done? I am using numpy matrix, if it makes any difference. I k...

JavaScript equivalent of Python's __setitem__

var obj = {} obj.__setitem__ = function(key, value){ this[key] = value * value } obj.x = 2 // 4 obj.y = 3 // 9 JavaScript doesn't have __setitem__ and this example obviously doesn't work. In python __setitem__ works like: class CustomDict(dict): def __setitem__(self, key, value): super(CustomDict, self).__setitem__(key, val...

Formatting "yesterday's" date in python

Python I need to find "yesterday's" date in this format: MMDDYY So for instance, today's date would be represented like this: 111009 I can do this for today easy of course but having trouble doing it automatically for "yesterday" ...

Get the size of a list in python?

items = [] items.append("shrooms") items.append("meth") items.append("weed") // FAKE METHOD:: items.amount() // should return 3 How I do it right? ...

Python JSON RPC server with ability to stream

I have come across several guides and packages on implementing a python JSON RPC server, e.g.: http://json-rpc.org/wiki/python-json-rpc http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/552751 http://pythonpaste.org/webob/jsonrpc-example.html They all do a good job in the sense that the server/application implementation is very...

tail read a growing dynamic file and extract two columns and then print a graph.

whats the best way to read a 1 GB file that gets time series data logged in it and generate a real time graph with two of its columns (one time and other a number)? I see that you have different ways of tailign the file. ...

In Python: how do I say: if line.partition('#' or 'tab') ... do something...

In Python: how do I say: line = line.partition('#' or 'tab')[0] ... do something with I know I can do: line = line.partition('#')[0] ... do something But what is the code for the tab character, and can I say # or tab? Update: I'm trying to say read the first word on each line, if you read a # then ignore everything after th...

Is there a library that can open and search through a pdf file?

Is there a library that can open and search through a pdf file? Preferably in C, python or ruby... ...

Making a multi-table inheritance design generic in Django

First of all, some links to pages I've used for reference: A SO question, and the Django docs on generic relations and multi-table inheritance. So far, I have a multi-table inheritance design set up. Objects (e.g: Car, Dog, Computer) can inherit an Item class. I need to be able to retrieve Items from the DB, get the subclass, and do stu...

What Jabber/XMPP libraries are available for PyS60 (Python for Symbian S60) interpreter?

I'm interested in developing a XMPP client on the mobile S60 Symbian platform using the Python interpreter PyS60. I've done a search on Google for possible libraries, but turned up empty. I'm hoping that by asking this on SO, I can get a definite answer on whether there is actually an existing library that I just hadn't had the luck to...

Pylons deployment questions

I'm a beginner with Pylons and I've mostly developed on my localhost using the built-in web server. I think it's time to start deployment for my personal blog, I have a Debian Lenny server with apache2-mpm-prefork module and mod_wsgi - I've never really used mod_wsgi or fastcgi and I hear either of these are the way to go. My questions:...

Can someone fix this python problem for me? (cannot find a module...)

I installed Yahoo BOSS (it's a python installation that allows you to use their search features). I followed everything perfectly. However, when I run the example, to confirm that it works, I got this: $python ex3.py Traceback (most recent call last): File "ex3.py", line 16, in ? from yos.yql import db File "/usr/lib/python2.4...

proper usage of super built-in method in python

I get some error that I can't figure out. Any clue what is wrong with my sample code? class B: def meth(self, arg): print arg class C(B): def meth(self, arg): super(C, self).meth(arg) print C().meth(1) I got the sample test code from help of 'super' built-in method. The class "C" is the Here is the error: ...

Python 3 Function List

I've just started learning Python and would like to know if there is a searchable list of Python (3.1) functions available online, like there is for PHP (php.net)? Thanks. ...

Python, Asyncore and forks.

Hey there. Just for starters, I used Twisted and SocketServer with both ForkMixIn, ThreadMixIn and tried the "thread-pool" recepies. However, I wanted to make something particular work in Python. Alittle background. Previously I wrote in C a simple TCP deamon that would bind to a socket and listen on it, then pre-fork X many times and...

How to load a bitmap on a window on PyQt

I currently have a PIL Image that I'd like to display on a PyQt window. I know this must be easy, but I can't find anywhere how to do it. Could anyone give me a hand on this? Here is the code of the window I currently have: import sys from PyQt4 import QtGui class Window(QtGui.QWidget): def __init__(self, parent=None): QtGu...

Mac OS X app/service and stdin?

I'm debugging a service I'm developing, which basically will open my .app and pass it some data to stdin. But it doesn't seem like it's possible to something like: open -a myapp.app < foo_in.txt Is it possible to pass stuff to an .app's stdin at all? Edit: Sorry, I should have posted this on SO and been more clear. What I'm trying to...

Peak-finding algorithm for Python/SciPy

I can write something myself by finding zero-crossings of the first derivative or something, but it seems like a common-enough function to be included in standard libraries. Anyone know of one? My particular application is a 2D array, but usually it would be used for finding peaks in FFTs, etc. Specifically, in these kinds of problems...

What if one of my programs runs in python 2.4, but IMPORTS something that requires python 2.5?

Then how do I import that? I run everything in python 2.4, but one of my scripts import xml.etree.ElementTree...which is only Python 2.5 ...