python

Google App Engine - headers[] and headers.add_header() for cache control

What is the proper way to set cache control? Sometimes I see the use of headers[] self.response.headers["Pragma"]="no-cache" self.response.headers["Cache-Control"]="no-cache, no-store, must-revalidate, pre-check=0, post-check=0" self.response.headers["Expires"]="Thu, 01 Dec 1994 16:00:00" Other times, I see headers.add_header() self...

I have a serial Python application that takes hours to process, how can I decrease the time it takes to run?

Could someone please post a few examples of multi-threaded python? I am searching all over the internet but cannot find a simple, easy-to-replicate tutorial. Simple examples are fine. I have written a program which takes a few hours to run serially--I am hoping I can bring it's run time down to minutes after multi-threading it. ...

PIL: Convert RGB image to a specific 8-bit palette?

Using the Python Imaging Library, I can call img.convert("P", palette=Image.ADAPTIVE) or img.convert("P", palette=Image.WEB) but is there a way to convert to an arbitrary palette? p = [] for i in range(0, 256): p.append(i, 0, 0) img.convert("P", palette=p) where it'll map each pixel to the closest colour found in the image? ...

Python: __init__() takes exactly 2 arguments (3 given)

Hi, this is my first question on StackOverflow, so please tell me how I can improve it in the comments. I am writing a program to find adapters, and have made a class called 'Adapter'. When I pass in two arguments IDLE gives me an error saying I passed in three! Here is the code and stack trace: #This is the adapter class for the adapt...

Automatic task execution on google app engine development server (python)

The docs for the python dev server say this about running tasks: When your app is running in the development server, task queues are not processed automatically. Instead, task queues accrue tasks which you can examine and execute from the developer console... But the release notes for version 1.3.4 of the python sdk (whic...

Python syntax for and/or'ing things together?

I'm trying to devise a scheme for validating form fields. I've decided you can pass in a list of validators to each field like, Field(validators=[email_validator, required_validator]) But then I thought, what if you wanted to or the validators together, rather than anding them? For example, a field that accepts either a Canadian posta...

Python proxy question

Is it possible to filter all outgoing connections through a HTTPS or SOCKS proxy? I have a script that users various apis & calls scripts that use mechanize/urllib. I'd like to filter every connection through a proxy, setting the proxy in my 'main' script (the one that calls all the apis). Is this possible? ...

Py-Postgresql and Raritan PowerIQ - Can't seem to find table?

Hi, I'm trying to write some Python3 to interface with the backend PostgreSQL server on a Raritan Power IQ (http://www.raritan.com/products/power-management/power-iq/) system. I've used pgAdminIII to connect to the server, and it connects fine with my credentials. I can see the databases, as well as the schemas in each database. I'm n...

best way to convert the this html file into an xml file using python

this html is here : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body> <div bgcolor="#48486c"> <table width="720" border="0" cellspacing="0" cellpadding="0" align="center" background="http://title.jpg" height="130"> ...

Drawing a polygon in pygame

hello friends, i am jaison i like to build an application for land survey process. for that i need to plot points in a canvas for a given gsi file. for example the points be a. .b c. .d .e these are the 5 points and i need to develop a tool to connect these points by line. while closin...

Python write to file

Hello, I've got a little problem here. I'm converting binary to ascii, in order to compress data. All seems to work fine, but when I convert '11011011' to ascii and try to write it into file, I keep getting error UnicodeEncodeError: 'charmap' codec can't encode character '\xdb' in position 0: character maps to Here's my code: b...

Following a Dynamic Score

I have little to no formal discrete math training, and have run into a wee bit of an issue. I am trying to write an agent which reads in a human player's (arbitrary) score and scores a point every so often. The agent needs to "lag behind" and "catch up" every so often, so that the human player believes there is some competition going on....

Interpreter in Python: Making your own programming language?

Remember, this is using python. Well, I was fiddling around with an app I made called Pyline, today. It is a command line-like interface, with some cool features. However, I had an idea while making it: Since its like a "OS", wont it have its own language? Well, I have seen some articles online on how to make a interpreter, and parser, ...

python search from tag

hi i need help with python programming: i need a command which can search all the words between tags from a text file. for example in the text file has <concept> food </concept>. i need to search all the words between <concept> and </concept> and display them. can anybody help please....... ...

How can I check if there exist any reverse element in list of dict without looping on it

My list is like l1 = [ {k1:v1} , {k2:v2}, {v1:k1} ] Is there any better way to check if any dictionary in the list is having reverse pair? ...

error with parse funcion in lxml

Hi all! i have installed lxml2.2.2 on windows platform(i m using python version 2.6.5).i tried this simple command: from lxml.html import parse p= parse(‘http://www.google.com’).getroot() but i am getting the following error: Traceback (most recent call last): File “”, line 1, in p=parse(‘http://www.google.com’).getroot() File “C:...

How to split strings based on capitalization?

Possible Duplicate: Python: Split a string at uppercase letters I'm trying to figure out how to change TwoWords into Two Words and I can't think of a way to do it. I need to split based on where it's capitalized, that will always be a new word. Does anyone have any suggestions? In python. ...

django tar generation on request

Greetings, By using Django, I want to generate a tar.gz which contains the files below, and render a tar.gz file: Content from an Ubuntu server: /home/user/myfolder /home/user/image.jpg an xml file from www.mysite.com/foo.xml (which is a dynamicly generated xml file. Rendered tar.gz file myfolder/ content/ ..... ...

how to get auth_user in python web request

I'm new to python . I want to make a basic auth in a web project , is there any way get HTTP authentication variables like the '$_SERVER['php_auth_user']' in php ? I'm using the FF's torando server. ...

I/O Reading from a file.

f = open('boo.txt') line = f.readline() print line f.close() How can I make it read a different line or a random line everytime I open the script, instead of just printing out the first line eveytime. ...