python

Google App Engine: how to parallelize downloads using TaskQueue or Async Urlfetch?

My Gae application retrieves JSON data from a third party site; given an ID representing the item to download , the item's data on this site is organized in multiple pages so my code has to download chunks of data, page after page, until the data of the last available page is retrieved. My simplified code looks like this: class FetchDat...

How to compare unicode strings with entity ref to non-unicode string

I am evaluating hundreds of thousands of html files. I am looking for particular parts of the files. There can be small variations in the way the files were created For example, in one file I can have a section heading (after I converted it to upper and split then joined the text to get rid of possibly inconsistent white space: u'KEY...

Deleting an arbitrary chunk of a file

What is the most efficient way to delete an arbitrary chunk of a file, given the start and end offsets? I'd prefer to use Python, but I can fall back to C if I have to. Say the file is this ..............xxxxxxxx---------------- I want to remove a chunk of it: ..............[xxxxxxxx]---------------- After the operation it should...

Does anyone know of a script to convert pygtk to tk

I have a fairly large work project that uses pygtk for the GUI and I need reduce the dependencies and convert to tkinter. Does anyone know of a script to convert exisiting pygtk code to tkinter? ...

Regular expressions split and match

>>> zznew '...0002211 118 7.5 "Weeds" (2005) {The Love Circle Overlap (#4.10)}' >>> re.split('\(+\d+\)',zznew) ['...0002211 118 7.5 "Weeds" ', ' {The Love Circle Overlap (#4.10)}'] >>> m = re.match('\(+\d+\)',zznew) >>> m.groups() Traceback (most recent call last): File "<pyshell#104>", line 1, in <module> m.groups() AttributeEr...

Unable to set custom permissions in Django

Hi, I'm trying to setup some custom permissions for a Django application, but can't seem to get it working. The official documentation is a little scant, and doesn't mention (at least that I can find) how to actually set a permission? Based on a few 3rd party tutorials I found, I've extended the User class and it seems to work OK: from...

Constructing a random string

How to construct a string to have more than 5 characters and maximum of 15 characters using random function in python import string letters = list(string.lowercase) ...

Determining a timezone in Python

Given a local timestamp and a UTC timestamp, is it possible to determine the timezone and whether DST is in effect? ...

How do I read a random line from one file in python?

Is there a built-in method to do it? If not how can I do this without costing too much overhead? ...

GAE bulkloader : entity missing from the auto-generated bulkloader.yaml

Hi, I am migrating a django application to GAE,and am going to use bulkloader to upload existing data. The model is quite simple, basically there are two models: class Tag(db.Model): name = db.StringProperty (required=True) class Entry(db.Model): # some properties ... # ... tags = db.ListProperty(db.Key) I ...

Python shell and execfile scope

I'm working from inside an ipython shell and often need to reload the script files that contain my functions-under-construction. Inside my main.py I have: def myreload(): execfile("main.py") execfile("otherfile.py") Calling myreload() works fine if I have already ran in the same ipython session the execfile commands directly. ...

difference between random randint vs randrange

the only difference that i know between randrange and randint is that andrange([start], stop[, step]) you can use the step and random.randrange(0,1) will not considerate the last item and randint(0,1) return a choice inclusive of the last item so, i can't find a reason for explain why randrange(0,1) doesn't return 0 or 1, why exist rand...

How do I modify a datastream on the fly?

Possible Duplicate: modify a datastream on the fly I need to hijack and modify a datastream. The stream consists of fixed-width commands. Each command is a new line, and the documentation says that each command starts and ends with an STX/ETX (start and end of text) pair. The sending system is using serial, but is attacked to...

Is it possible to run linux on hand-held tablets?

I want to run a django app on a hand-held device. It'll need to run Python (obviously) and will write its data to an SQLite database. Are there any tablets available that will let me do this? Specifically, if I bought an Android tablet, would I have to/be able to install linux instead, or would I be able to run it under Android? ...

Why is this pickled data not unpickling after transfer over a network?

logexample.py logs over the network using logging.handlers.DatagramHandler, which pickles(protocol 1) the data it sends. logserver.py is supposed to unpickle and print to screen, but instead it raises an error. If I use pickle.loads then KeyError: '\x00' and if I use cPickle.loads its an EOFError The files are here - http://gist.github...

Python, parse html form

Hello, how i can get input from the html forms. To receive such dictionary: form = [('name' = 'somename', 'type' = 'text', 'value':''},{' name' = 'somename', 'type' = 'submit', 'value': ' submit '). Sorry for my English. ...

Python error "IOError: [Errno 2] No such file or directory" but file is there

I am trying to read a csv file and I am getting the error above but the file is there. The line giving the error is infilequery = file('D:\x88_2.csv','rb') and I get the error below. Traceback (most recent call last): File "C:\Python26\usrapply_onemol2.py", line 14, in infilequery = file('D:\x88_2.csv','rb') IOError: [Errn...

Does readlines() return a list or an iterator in Python 3?

I've read in "Dive into Python 3" that "The readlines() method now returns an iterator, so it is just as efficient as xreadlines() was in Python 2". See here: http://diveintopython3.org/porting-code-to-python-3-with-2to3.html . I'm not sure that it's true because they don't mention it here: http://docs.python.org/release/3.0.1/whatsnew/3...

What substitutes xreadlines() in Python 3?

In Python 2, file objects had an xreadlines() method which returned an iterator that would read the file one line at a time. In Python 3, the xreadlines() method no longer exists, and realines() still returns a list (not an iterator). Does Python 3 has something similar to xreadlines()? I know I can do for line in f: instead of for ...

MySQL database: lua or python

Under preferences(Menu)/general (Tab)/ Interactive GRT Shell Language: lua or python. What is the difference? I use MyQSL for database and involve mostly binary. ...