python

How to send a string from a python script at Google App Engine to the browser client as a file

I have a python web-application running inside the Google App Engine. The application creates on user-demand a string and I want the string to be send to the browser client (application/octet-stream?) as a file. How can i realize this? ...

SQLAlchemy Column to Row Transformation and vice versa -- is it possible?

I'm looking for a SQLAlchemy only solution for converting a dict received from a form submission into a series of rows in the database, one for each field submitted. This is to handle preferences and settings that vary widely across applications. But, it's very likely applicable to creating pivot table like functionality. I've seen th...

Server Setup for iPhone Push Notifications

Hi all, I'm new to the whole push notifications thing, and was wondering if somebody could walk me through the process of getting a simple application up and running. I currently rent a server that I use to serve my website that runs cPanel X. How would I go about setting up the service? What software do I need to install on the serve...

Printing correct time using timezones, Python

Extends Ok, we are not having a good day today. When you attach the correct tzinfo object to a datetime instance, and then you strftime() it, it STILL comes out in UTC, seemingly ignoring the beautiful tzinfo object I attached to it. # python 2.5.4 now = datetime.now() print now.strftime( "%a %b %d %X" ) # %X is "locale's...

Google app engine after refresh from datastore

I want to set the .tzinfo of every datetime instance automatically as soon as it comes out of the datastore. So if I have class Message( db.Model ): creationTime = db.DateTimeProperty() someOtherTime = db.DateTimeProperty() ## I really want to define a method like this, ## that runs immediately AFTER an instance has ...

Rotate a quad around a centre point in OpenGL

Hello, I'm making a 2D game. I want to be able to render a texture on the screen after rotating it a certain amount around a centre point. Basically this is for a level rotation around a player. The player position being the rotation point and the direction of the player as the angle. This code wont work: def draw_texture(texture,offset...

QRadioButton and QVBoxLayOut

Hi all, I used next code to dynamically create a group of radio buttons: self.wPaymantType.qgbSomeSelectionGroup = QtGuig.QGroupBox() vbox = QtGui.QVBoxLayout() for row in listOfChoices: radio = QtGui.QRadioButton(row) if bIsFirst: radio.setChecked(True) bIsFirst = False if len(row.name) > nMaxLen: ...

How to format search autocompletion part lists?

I'm currently working on an AppEngine project, and I'd like to implement autocompletion of search terms. The items that can be searched for are reasonably unambiguous and short, so I was thinking of implementing it by giving each item a list of incomplete typings. So foobar would get a list like [f, fo, foo, foob, fooba, foobar]. The use...

How can I process xml asynchronously in python?

I have a large XML data file (>160M) to process, and it seems like SAX/expat/pulldom parsing is the way to go. I'd like to have a thread that sifts through the nodes and pushes nodes to be processed onto a queue, and then other worker threads pull the next available node off the queue and process it. I have the following (it should have...

python search replace using wildcards

hi somewhat confused.. but trying to do a search/repace using wildcards if i have something like: <blah.... ssf ff> <bl.... ssf dfggg ff> <b.... ssf ghhjj fhf> and i want to replace all of the above strings with say, <hh >t any thoughts/comments on how this can be accomplished? thanks update (thanks for the co...

Weird pynotify behaviour in Ubuntu 9.10

Hi, I wrote a small app and I am using pynotify to show some messages to the user. It all works fine here in arch, but when I tested it in Ubuntu, the behaviour was very weird. Because of the way Ubuntu shows notifications (as what seems to be a rip of of growl), I can't click on them, or interact with them in any way, for that matter....

How to swap adjacent bytes in a string of hex bytes (with or without regular expressions)

Given the string (or any length string with an even-number of word pairs): "12345678" How would I swap adjacent "words"? The result I want is "34127856" As well as, when that's done I need to swap the longs. The result I want is: "78563412" ...

Symbolic Group Names (like in Python) in Ruby Regular Expression

Came across this handy regular expression utility in Python (I am a beginner in Python). e.g. By using the regexp (?P<id>[a-zA-Z_]\w*) I can refer to the matched data as m.group('id') (Full documentation: look for "symbolic group name" here) In Ruby, we can access the matched references using $1, $2 or using the MatchData object...

Python Window Activation

How would I programmatically activate a window in Windows using Python? I'm sending keystrokes to it and at the moment I'm just making sure it's the last application used then sending the keystroke Alt+Tab to switch over to it from the DOS console. Is there a better way (since I've learned by experience that this way is by no means foolp...

ValueError: no such test method in <class 'myapp.tests.SessionTestCase'>: runTest

I have a test case: class LoginTestCase(unittest.TestCase): ... I'd like to use it in a different test case: class EditProfileTestCase(unittest.TestCase): def __init__(self): self.t = LoginTestCase() self.t.login() This raises: ValueError: no such test method in <class 'LoginTest: runTest` I looked at the unittest ...

Python dictionary key order when printing

s={ 'userName': "4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf", 'userNameMin': "\u4e0d\u80fd\u5c0f\u4e8e4\u4e2a\u5b57", 'userNameMax': "\u4e0d\u80fd\u8d85\u8fc712\u4e2a\u5b57", 'userNameExist': "\u8be5\u7528\u6237\u540d\u5df2\u88ab\u6ce8\u518c\u4e86\uff0c\u8bf7\u6362\u6362",...

Problems enabling a quit function in Python

Hi, I'm pretty new to programming in general and I'm creating a small game for my younger sister... I have a while loop in which I want to have an option to quit the game, but none of the quitting techniques I know of seem to work: #main game: while 1: input_event_1 = gui.buttonbox( msg = 'Hello, what would you like to do w...

Basic Hello World in Python isn't working.

I'm completely lost as to why this isn't working. Should work precisely, right? UserName = input("Please enter your name: ") print ("Hello Mr. " + UserName) raw_input("<Press Enter to quit.>") I get this exception: Traceback (most recent call last): File "Test1.py", line 1, in UserName = input("Please enter your name: "...

What version of Python should I use if I'm a new to Python?

If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc: What version of Python should I use? I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn some things that won't carry over well into Python 3. For exam...

python datetime localization

What do I need to do (modules to load, locale methods to invoke, etc.) so that when I call: datetime.date(2009,1,16).strftime("%A %Y-%b-%d") instead of getting: Out[20]: 'Friday 2009-Jan-16' i get spanish/french/german/... output Out[20]: 'Viernes 2009-Ene-16' without having to change my whole operating system's locale (i.e. jus...