python

How to get a Blob size? (Python Google App Engine)

http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#Blob ...

Reference function or create a new function that only calls another?

def a(something): return something*something #Case I - referencing b = a #Case II - creating a new function to call the first def b(something): return a(something) Which is better style? Are there drawbacks to either? ...

What good tutorials exist for learning pycURL?

I'm planning on building my own FTP client in Python for learning purposes. I'm planning on using PycURL but the documentation seems to be lacking. What good tutorials are there for learning pycURL? ...

my code example imitate 'memoize' function in django.utils.functional.py,why error.

def a(): print 'aa' def b(): print 'bb' def c(*x): print x def d(x,y): c(*(x+y)) d(a,b) Traceback (most recent call last): File "D:\zjm_code\mysite\zjmbooks\a.py", line 15, in <module> d(a,b) File "D:\zjm_code\mysite\zjmbooks\a.py", line 13, in d c(*(x+y)) TypeError: unsupported operand type(s) for +: 'fun...

How to get something to appear on every page in Django?

I'm curious as to the best-practise way to handle having something appear on every page, or on a number of pages without having to assign the data manually to every page like so: # views.py def page0(request): return render_to_response( "core/index.html", { "locality": getCityForm(request.user), ...

Can't find thread.py

What does this code mean? try: import thread except ImportError: del _sys.modules[__name__]#why raise But I can't find thread.py. why,del _sys.modules[__name__] ...

Am I using the webbrowser.open() wrong, or does it not work as advertised? (Python)

Given this python code: import webbrowser webbrowser.open("http://slashdot.org",new=0) webbrowser.open("http://cnn.com",new=0) I would expect a browser to open up, load the first website, then load the second website in the same window. However, it opens up in a new window (or new tab depending on which browser I'm using). Tried on ...

Skype - Transferring calls with Python

I want to write an application similar to this in Python. Using Skype4Py, I've managed to setup a system that takes two landline numbers and joins them in a conference call. The problem with it is that Skype doesn't let you have multiple concurrent calls, which is what I need. I was going to have a play around with Asterisk when I foun...

How does Gedit expose its api to python for plugins?

I'm starting a medium (academic) project in C++ for which I need users to be able to write small scripts, which interact directly with the main program. My first thought as an aproach to this was to make something like Gedit does with it's plugins (in fact I thought about it because it is something very similar to what I need to do.) I ...

Find which python modules are being imported

What's an easy way of finding all the python modules from a particular package that are being used in an application? ...

Sanitizing user-provided SQL with Python?

I'm working on a small app which will help browse the data generated by vim-logging, and I'd like to allow people to run arbitrary SQL queries against the datasets. How can I do that safely? For example, I'd like to let someone enter, say, SELECT file_type, count(*) FROM commands GROUP BY file_type, then send the result back to their w...

Qt Python Combo-Box "currentIndexChanged" firing twice

I have a combo, which is showing some awkward behavior. Given a list of options from the combo-box, the user should pick the name of a city clicking with the mouse. Here is the code: QtCore.QObject.connect(self.comboCity, QtCore.SIGNAL("currentIndexChanged(QString)"), self.checkChosenCity) def checkChosenCity(self): ...

Determining the number of possible combinations

I'm trying to figure out how many possible ways there are to combine various elements form this string. "{Hello|Hi|Hey} {world|earth}{!|.|?}" Where one item (separated by a pipe/|) is selected at random from each group ({}) and combined into a single string. So the above "template" could produce: Hello world. Hi earth? Hey world. Hi...

sharing objects between module in GAE

To share a state(e.g. user) between a module in django people sometime use thread local storage, but as google app engine follows CGI standard and keeps state of a request in os.environ , can I share objects between two modules just by setting it e.g. mod1.my_data = {} and now any other module can get handle to my_data? without worryin...

Faster method of reading screen pixel in Python than PIL?

Currently I'm using a pixel reader via AutoItv3 to perform some actions in a program that is running direct X; A game. Right now the program works fine but as an exercise I've been rewriting it in python. Right now I can do: import ImageGrab # Part of PIL image = ImageGrab.grab() #Define an area to capture. rgb = image.getpix...

Alternative pygame resources

Hi, I have been trying to access the pygame website for a few weeks now, and I can't get to it. I doubt it's down, so I have to conclude that it's blocked because I am in China. I have no idea why. Anyways, I want the pygame documentation, but all the download links I fond lead back to pygame.org (which I does not even begin loading, it'...

Pygame error: display surface quit: Why?

Sorry if this question is dumb, but I am writing from China and for some unfathomable reason a lot of websites having to do with pygame are blocked. I can't access pygame.org, I have not been able to download the docs or even look at message boards having to do with pygame! WEIRD! Anyways, I am a pygame newb and I need help with two thi...

what is the 'decimal.getcontext().copy()' mean .

import decimal # Decimals a=decimal.getcontext().copy() print a thanks. what is the useful of a. ...

python mechanize proxy support question

Hello All Happy New Year! i have some question about python mechanize 's proxy support. im making some web client script, and i would like to insert proxy support function into my script. for example ,if i have such like following some script. how can i add proxy support into my mechanize script? i was look for some reference ,...

Is it safe to use user input for Python's regular expressions?

I would like to let my users use regular expressions for some features. I'm curious what the implications are of passing user input to re.compile(). I assume there is no way for a user to give me a string that could let them execute arbitrary code. The dangers I have thought of are: The user could pass input that raises an exception...