python

Modifying a Python class

I'd like to modify all classes in Python. For example str and int and others like Person(object). I'd like to add an attribute to them and to change the way its methods works. Which is the best approach for this? Metaclasses? ...

How to force python's VM to print a stack trace?

I'm dealing with a python-written server that locks up, and stops working, including logging. I wonder if there's a python equivalent to java's "kill -3" signal that at least prints the current stacktrace. ...

Custom address field in Django Model

What's the common practice to represent postal addresses in Django models? Is there a library for custom model fields that include postal address fields and potentially handle validation and formatting? If no library exists, how can I write one? Can I represent a composite field (a field that gets serialized to multiple columns in db)...

After handshake of websocket, chrome disconnects. Is this due to domain mismatch? Or Chrome bug?

I made my own simple WebSocket server in Python but Chrome 4.0.249.78 dev (36714) ALWAYS disconnects after the handshake. To make sure it wasn't my code I used the WebSocket server found at http://stackoverflow.com/questions/2153294?tab=newest#tab-top to test it and got the same result (below). listening... connection! GET / HTTP/1.1 Up...

Multiplying a subset of a list of integers together in python

Let's say I have a list of 10 integers and I want the result of multiplying the first 5 together. Is there a pythonic way of doing this? Python seems to be great with lists :) ...

Hotmail API: how retrieve contacts

How can I retrieve contacts from hotmail with python ? Is there any example ? Thanks ^_^ ...

What does this Openid error mean: Error attempting to use stored discovery information

I'm attempting to setup an app using django-openid and openid. I'm getting the following errors and I can't figure out what is causing them. [Fri Jan 29 13:29:20 2010] [error] Generated checkid_setup request to https://www.google.com/accounts/o8/ud with assocication XXXXXXXXXXXXXX [Fri Jan 29 13:29:26 2010] [error] Error attempting to...

What would be the jquery equivalent of 'Dive into python'?

I need to , well, dive into client side programming. Is there an equivalent to 'Dive into python' for jquery? I see that jquery 1.4 has been released. Does this change anything w.r.t answers? ...

Removing html tags from a text using Regular Expression in python

I'm trying to look at a html file and remove all the tags from it so that only the text is left but I'm having a problem with my regex. This is what I have so far. import urllib.request, re def test(url): html = str(urllib.request.urlopen(url).read()) print(re.findall('<[\w\/\.\w]*>',html)) The html is a simple page with a few links a...

Python: namedtuple._replace() doesn't work as descrbed in the documentation.

I was having trouble implementing 'namedtuple._replace()', so I copied the code right off of the documentation: Point = namedtuple('Point', 'x,y') p = Point(x=11, y=22) p._replace(x=33) print p and I got: Point(x=11, y=22) instead of: Point(x=33, y=22) as is shown in the doc. I'm using Python 6.2 on Windows 7 edit: oops- tha...

New to Python; Beginners Project ideas.

I am new to python, This Project is a Free user-contributed multilingual dictionary, Located http://github.com/klanestro/vortaro I have a few Ideas that I would use php But don't know where to start studying. Like in this code how does it search the database for the users word. How does that relate to the URL's as in one language ...

What vim plugins mix results in this interface

I saw this VIM UI and thought it was awesome and now I want it. Anyone know what plugins the author is using? http://werkzeug.pocoo.org/wiki30/files/wiki30.mp4 ...

Windows live api for python

Hi at all, I have read documentation about Windows Live API: http://msdn.microsoft.com/en-us/library/bb463989.aspx But how can I retrieve contacts from hotmail with python ? Is there any example ? ...

Open source Python project to contribute to

Until recently, I was a Linux Administrator for a company which went out of business. I don't need money so I don't plan to work for a while. With all this free time, I'd like to work on my programming skills. Of all the languages I am familiar with I have the most experience with Python. I've searched projects on Github and Sourceforge...

Casting from list of lists of strings to list of lists of ints in python

I'm reading some numbers from a data source that represent xy coordinates that I'll be using for a TSP-esque problem. I'm new to python, so I'm trying to make the most of lists. After reading and parsing through the data, I'm left with a list of string lists that looks like this: [['565.0', '575.0'], ['1215.0', '245.0'], ...youge...

How would you further lock down a Google App Engine app executing untrusted code?

We are currently using Google App Engine to evaluate solutions to Python problems submitted by students. We have moved all of the untrusted code execution off to a separate GAE application that doesn't use the datastore. Everything seems to be working fine for the 50+ problems we have uploaded, but I'm curious what security holes remain ...

In Python, how do you programmatically execute unit tests stored in a string?

The following code is used to execute doctests in a Google App Engine app. How would you do this for tests written as unit test asserts rather than as doctests? #The solution and tests are untrusted code passed in to the GAE app. solution = 'b=5' unittest = 'assertEqual(b, 5)' #Here is the doctest version as a reference. solution = ...

Python: how to check if an object is an instance of a namedtuple?

How do I check if an object is an instance of a Named tuple? ...

Using httplib2 in python 3 properly? (Timeout problems)

Hey, first time post, I'm really stuck on httplib2. I've been reading up on it from diveintopython3.org, but it mentions nothing about a timeout function. I look up the documentation, but the only thing I see is an ability to put a timeout int but there are no units specified (seconds? milliseconds? What's the default if None?) This is w...

Getting next element while cycling through a list

li = [0, 1, 2, 3] running = True while running: for elem in li: thiselem = elem nextelem = li[li.index(elem)+1] When this reaches the last element, an IndexError is raised (as is the case for any list, tuple, dictionary, or string that is iterated). I actually want at that point for nextelem to equal li[0]. My rath...