python

Google App Engine or Django?

I've been learning Python and now I'd like to learn a Python-based web framework. I'm considering Google App Engine and Django. Which one should I choose? What are their unique features and learning curves? ...

PyQtWebkit and java script

Hello, I have a page with js. I need get dom after js execute at webpage. Js inserts text in the div with name 'sdl'. I need get value between . Value can not be parsed in js source, it is generated by Js. How to do it? Sorry for my english. ...

Embedding Matplotlib in Tkinter, display problems

I'm currently trying to graph a sphere in a tkinter window using matplotlib. How do I go about making the display square? I'd like the sphere to have as little distortion as possible. My code: #!/usr/bin/env python import matplotlib matplotlib.use('TkAgg') from mpl_toolkits.mplot3d import axes3d,Axes3D import matplotlib.pyplot as plt...

Testing if a list contains another list with Python

How can I test if a list contains another list. Say there was a function called contains: contains([1,2], [-1, 0, 1, 2]) # Returns [2, 3] (conatins returns [start, end]) contains([1,3], [-1, 0, 1, 2]) # Returns False contains([1, 2], [[1, 2], 3) # Returns False contains([[1, 2]], [[1, 2], 3]) # Returns [0, 0] Edit: contains([2, 1], [...

convert a json string to python object

Is it possible to convert a json string (for e.g. the one returned from the twitter search json service) to simple string objects. Here is a small representation of data returned from the json service: { results:[...], "max_id":1346534, "since_id":0, "refresh_url":"?since_id=26202877001&q=twitter", . . . } Lets say that I somehow stor...

get index of character in python list

What would be the best way to find the index of a specified character in a list containing multiple characters? ...

Wrapping exceptions in Python

I'm working on a mail-sending library, and I want to be able to catch exceptions produced by the senders (SMTP, Google AppEngine, etc.) and wrap them in easily catchable exceptions specific to my library (ConnectionError, MessageSendError, etc.), with the original traceback intact so it can be debugged. What is the best way to do this in...

Django not cascading on delete.

I'm realizing more and more that I'm still a Django noob, I can't seem to figure out what's happening with my data model and why it's not cascading deletes. Here is my model. class message(models.Model): msg_text = models.CharField(max_length = 9900) date_time = models.DateTimeField() is_read = models.BooleanField(defaul...

Installing psycopg2 in virtualenv (Ubuntu 10.04, Python 2.5)

I had problems installing psycopg2 in a virtualenv. I tried different things explained there: http://www.saltycrane.com/blog/2009/07/using-psycopg2-virtualenv-ubuntu-jaunty/ The last thing I tried is this... I created a virtualenv with -p python2.5 --no-site-packages I installed libpq-dev: apt-get install libpq-dev In the virtualenv...

Deciding on RESTful Architecture for my Python code API

I would like to build something like this Datastore | mycode.py | RESTful API | mywebapp.py(Django or Tornado) I checked Piston for Django but it seems that this way I am going to be tied to Django, I would rather have a RESTful API for mycode.py that is consumable by more than one REST client and also can consume it from a REST client...

Calling variable superclass method

I'm trying to call a method of the superclass by using a variable method name. Normally, I would see the following two lines of code as equivalent: someObj.method() someObj.__getattribute__( 'method' )() And in fact I believe, this is also what actually happens when I use the first line. However, in the following example, the second l...

alphabetically sorted if statement not working

The if statement below has a problem in it somewhere and I can not figure it out. Any conventions or method misuses that might be causing it to not function right? checkList is a user inputed sentence and lis is a large list of words. def realCheck(checkList): string = "".join(checkList) print string wordList = str...

Is Celery appropriate for use with many small, distributed systems?

I'm writing some software which will manage a few hundred small systems in “the field” over an intermittent 3G (or similar) connection. Home base will need to send jobs to the systems in the field (eg, “report on your status”, “update your software”, etc), and the systems in the field will need to send jobs back to the server (eg, “a fa...

Getting current class in method call

class A: def x ( self ): print( self.__class__ ) class B ( A ): pass b = B() b.x() In the above situation, is there any way for the method x to get a reference to class A instead of B? Of course simply writing print( A ) is not allowed, as I want to add some functionality with a decorator that needs the class A (and a...

URL Builder for CherryPy

After using werkzeug as a web framework (which is great and simple, but doesnt support some features), i'm now trying cherrypy. Now what I miss in cherrypy is werkzeug's elegant way of building urls (e.g. for links in templates) using the name of a decorated function like this: @expose('/archive/<int:year>/<int:month>') def archive(req...

Python set iteration order varies from run to run

Why does the iteration order of a Python set (with the same contents) vary from run to run, and what are my options for making it consistent from run to run? I understand that the iteration order for a Python set is arbitrary. If I put 'a', 'b', and 'c' into a set and then iterate them, they may come back out in any order. What I've o...

Trying to group values?

I have some data like this: 1 2 3 4 5 9 2 6 3 7 and am looking for an output like this (group-id and the members of that group): 1: 1 2 6 2: 3 4 7 3: 5 9 First row because 1 is "connected" to 2 and 2 is connected to 6. Second row because 3 is connected to 4 and 3 is connected to 7 This looked to me like a graph traversal but the f...

Python comparing two lists

Hello I wanna compare two lists like this a=[1,2] b=10,20] compare(a,b) will return True if each element in a is > corresponding element in b so compare( [1,2] > [3,4] ) is True compare( [1,20] > [3,4] ) is False hiow to do this the pythonic way Cheers ...

Stdout captured from pipe in Python is truncated

I want to capture the ouput of dpkg --list | grep linux-image in Python 2.6.5 on Ubuntu 10.04. from subprocess import Popen from subprocess import PIPE p1 = Popen(["dpkg", "--list"], stdout=PIPE) p2 = Popen(["grep", "linux-image"], stdin=p1.stdout, stdout=PIPE) stdout = p2.communicate()[0] The content of stdout is: >>> print stdou...

Python equivalent of ActionScript 3's restParam

In ActionScript 3 (Flash's programming language, very similar to Java - to the point that it's disturbing), if I was defining a function and wanted it to be called with endless parameters, I could do this (restParam, I thought it was called): function annihilateUnicorns(...unicorns):String { for(var i:int = 0; i<unicorns.length; i++...