python

Check maxlen of deque in python 2.6

Hi, I have had to change from python 2.7 to 2.6. I've been using a deque with the maxlen property and have been checking what the maxlen is. Apparently you can use maxlen in python 2.6, but in 2.6 deques do not have a maxlen attribute. What is the cleanest way to check what the maxlen of a deque is in python 2.6? In 2.7: from collectio...

What is a Class in python, what does it do, why is it needed?

Possible Duplicate: Do I correctly understand what a class is? Before you rant and rage and scream at me, understand that I tried searching everywhere, from google to this very site on what exactly a class in python is. I have found definitions of sorts, but have never been able to understand them fully. So here's the question...

Closures in Python

I have seen & used nested functions in Python. They match the definition of a closure. It is not closure simply because it is not used by external world? UPDATE: I was reading about closures & it got me thinking about this concept with respect to Python. A little bit of search got me to the article someone in the comments pointed to. B...

When running Celery with Django's manage.py command, it returns a strange error

When I run the following command, it produces the following error: % python manage.py celeryd -l INFO ~/Workspace/django-projects/project/src Traceback (most recent call last): File "manage.py", line 11, in <module> execute_manager(...

Python facebook sdk offline_access

I am using facebook python sdk with app engine. I am able to access the user information when the user is online. I have already included <fb:login-button perms="read_stream,publish_stream,offline_access"></fb:login-button> in my index page. User has also allowed for offline_access. However, I am having problem accessing and us...

Process escape sequences in a string in Python

Sometimes when I get input from a file or the user, I get a string with escape sequences in it. I would like to process the escape sequences in the same way that Python processes escape sequences in string literals. For example, let's say myString is defined as: >>> myString = "spam\\neggs" >>> print(myString) spam\neggs I want a fun...

python, functions combination via names and chain them to invoke in-a-go?

All, I have confuse below may need your help suppose I have a row based variable length data matrix 93 77 96 85 50 69 54 16 39 91 59 38 64 30 18 50 43 9 74 94 44 87 95 89 ... I want to generate result data via above source with different generating algorithms while the different range selection algorithms, take ...

pygtk FileChooserDialog slows down interpreter

I'm trying to use FileChooserDialog to get a native gnome dialog box in a python script. After the script executes, my ipython -pylab prompt experiences a significant slow down. This problem also exists from a plain python prompt. I've isolated the problem to the dialog box. The following example (which has been posted elsewhere as a...

(Python) How can I print a varible to a Tweepy "API.update_status()" command?

Hello there! I am trying to add some information to a python script that posts the information to twitter. Here is the code so far: #!/usr/bin/python import os import subprocess import psutil import sys import tweepy #---------------------------------------- # Gives a human-readable uptime string def uptime(): try: f = open( "/pr...

how can I implement iteritems function for my custom iterator?

Objective of the following program is to learn python generators and iterator implementation,in order to understand Python magic methods, I've started working on the following example, Here goes my code, I've stucked implementing the iteritems function - also I want to know whether I'm going on right direction or I'm conceptually wrong ...

Finding the index of a string in a tuple

Tup = ('string1','string2','string3') My program returned string2 how do I get it's index within Tup? ...

How do I use a variable as table name in Django?

I'd like to do the following: for table in table_list: 'table'.samefield = newvalue ...

Django response query

What would be the correct statements for the below two.I want to send the base variable to my template which keeps varying but there will be an error if i send {'form': form,'msg' : msg} in the second statement return render_to_response('chatlist/newchat.html', context_instance=RequestContext(request,{'form': form,'msg' : msg}),extra_co...

Using pip packages in python scripts

Hi, I've install this script via pip, but how to a reference these files as part of my script, do I need to use import or some other magic? Thanks ...

How do you decode a binary encoded mail message in Python?

I'm writing a Google App engine app that processes incoming mail, and here's the code I'm currently using to process mail messages: for content_type, body in email_bodies: #8bit bug in mail messages - see bug report here #http://code.google.com/p/googleappengine/issues/detail?id=2383 if body.encoding == '8bit': body.encoding = '7bit...

python function list chained executing?

Hi, In python I defined functions: def foo_1(p): return p + 1 def foo_2(p): return p + 1 def foo_3(p): return p + 1 def foo_4(p): return p + 1 def foo_5(p): return p + 1 I need execute those function as a chain may like this: foo_1(foo_2(foo_3(foo_4(foo_5(1))))) May I know if I can push the functions into a list then execute those...

I am a newbie of python, How to print some words input by user ?

My code as follow: #!/usr/bin/python #Filename:2_7.py text=raw_input("Enter string:") for ?? in range(??) print the ?? means I don't know how to write, could you please tell me if you know, thanks ...

How to write this exception in Python 2.6

Hi, I need to write an expection that if a string is null, then fire this exception. How to write this? Eg. str = get_str() if get_str() returns None or nothing. It should raise an exception. ...

Wondering whether I should just bail on using properties in python

Hi, I have been trying to use properties instead of specific setters and getters in my app. They seem more pythonic and generally make my code more readable. More readable except for one issue: Typos. consider the following simple example (note, my properties actually do some processing even though the examples here just set or retu...

how to update QtableView when model change in pyqt Or in qt?

hello i have a QtableView that has a QsqlTableModel. i want my model to check for the changes when a user hit (refresh button) but i can't find a way to update data. i tried model.reset() and model.update() but they didn't work for me . i've been trying to find a solution for a couple of days is it possible in anyway to re-read from d...