python

Python ctypes - how to handle arrays of strings

I'm trying to call an external library function that returns a NULL-terminated array of NULL-terminated strings. kernel32 = ctypes.windll.kernel32 buf = ctypes.create_unicode_buffer(1024) length = ctypes.c_int32() if kernel32.GetVolumePathNamesForVolumeNameW(ctypes.c_wchar_p(volume), buf, ctypes.sizeof(buf), ctypes.pointer(length)):...

Python multi-line input

Is there any way to have multi-line input in Python? Solutions I have seen don't allow you to edit past lines after you have pressed enter and have other problems. I am making a simple text editor in Python and I want to have a text input that can be multiline and pressing buttons like left or right would move the text cursor. I need it ...

pylons file uploading - access 1st file

Currently, I'm using request.params["filename"] to access uploaded files. In Pylons, what is the syntax to access a file if you don't know the filename, something like request.files[0]? ...

Splitting an SMS Reply

When replying to an SMS, I have a limit of 160 characters. I currently have code set up to take a reply (which can be >160) and split it into a list of multiple texts each <160. It's also set up so that it keeps words whole. I included it: repl='message to be sent. may be >160' texts=[] words=repl.split() curtext='' for word in words: ...

Calling Overriden Methods in Derived Class from Base Class

I was reading the Python docs about classes and came across this paragraph which I'm not sure about: Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same b...

What resources are there for A/B split-testing in Python?

There are several A/B split testing modules/plugins for Rails. http://github.com/paulmars/seven_minute_abs http://www.bingocardcreator.com/abingo http://vanity.labnotes.org/ etc. Is there anything similar for Python? ...

Clean Up HTML in Python

I'm aggregating content from a few external sources and am finding that some of it contains errors in its HTML/DOM. A good example would be HTML missing closing tags or malformed tag attributes. Is there a way to clean up the errors in Python natively or any third party modules I could install? ...

From the web to games

Hey guys! I'm a basic web developer. I know PHP, a little bit of Python and Ruby. JavaScript as well [some stuff]. I'm not a hardcore developer. I know what it takes do develop most of web cases. Now, I have this desire to go deeper and start developing games. I know it sounds a huge leap, but that is why I'm asking here. I already hav...

how to download data to b.csv that like a.csv format from gae localhost server .

my a.csv is: 001,哈哈大学 002,拉拉大学 003,啊啊啊大学 004,文网文大学 005,卡卡卡大学 006,请求权大学 007,凤飞飞大学 and my str_loader.py is : class College(db.Model): cid = db.StringProperty(required=True) name = db.StringProperty(required=True) class CollegeLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'College',...

wxPython: VirtualTreeListCtrl with millions of items

I would like to add 1,000,000+ entries to the root node of a TreeListCtrl. Therefore I would like to make it "virtual", i.e. work just like a virtual ListCtrl so that it's still fast and I can easily scroll around due to the currently-displayed items being loaded on-demand. But I can't use a virtual ListCtrl because I also want to be abl...

How to override equals() in google app engine data model type?

I'm using the Python libraries for Google App Engine. How can I override the equals() method on a class so that it judges equality on the user_id field of the following class: class UserAccount(db.Model): # compare all equality tests on user_id user = db.UserProperty(required=True) user_id = db.StringProperty(required=True)...

is a decorator in python exactly the same as calling a function on a function?

I thought that doing @f def g(): print 'hello' is exactly the same as def g(): print 'hello' g=f(g) But, I had this code, that uses contextlib.contextmanager: @contextlib.contextmanager def f(): print 1 yield print 2 with f: print 3 which works and yields 1 3 2 And when I tried to change it into def f()...

Python IRC Client

import socket, sys, string if len(sys.argv) !=4 : print "Usage: ./supabot.py <host> <port> <channel>" sys.exit(1) irc = sys.argv[1] port = int(sys.argv[2]) chan = sys.argv[3] sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sck.connect((irc, port)) sck.send('NICK supaBOT\r\n') sck.send('USER supaBOT supaBOT supaBOT :supa...

invoking yield for a generator in another function

suppose I have some manager object. This object's API has a main_hook function, that gets another function f as it's argument, and runs the given f in a loop, doing some stuff in between each iteration: def main_hook(self,f): while (self.shouldContinue()): #do some preparations f(self) #do some tear down No...

Google App Engine Python Authentication from API

I'm currently building a Python webapp on the Google App Engine and I want to expose various parts of my application via a JSON API. This API may be used in the form of a mobile client, or (for the purposes of testing) a headless Python script. I need to be able to authenticate users before they perform operations on the API. I notice t...

The _imaging C module is not installed

Hi there. I have a bit of a problem and don't know where to look for answers, hopefully someone has come across it. I have PIL(Python imaging library installed) when I run python import PILimport Image import _imaging I don't get errors. however running my app raises _imaging C module not installed ...

how to update data to gae localhost server from mysql ..

i follow this article : here to update data to gae localhost server from mysql. this is my str_loader.py is : class College(db.Model): cid = db.StringProperty(required=True) name = db.StringProperty(required=True) class MySQLLoader(bulkloader.Loader): def generate_records(self, filename): """Generates records from ...

printing unicode through a QProcess

I'm having some trouble handling unicode output from a QProcess. When I run the following example I get ?? instead of 中文. Can anyone tell me how to get the unicode output? from PyQt4.QtCore import * def on_ready_stdout(): byte_array = proc.readAllStandardOutput() print 'byte_array: ', byte_array print 'unicode: ', unicode...

Python | How to create complex dictionary

I want to create a data structure that will be parse as a JSON object. The out put must look like this and this should be a dynamic data structure. {"data": [{"type": "locale", "lat": -34.43778387240597, "lon": 150.04799169921876}, {"type": "poi", "lat": -34.96615974838191, "lon": 149.89967626953126}, {"type": "locale", "lat": -34.72271...

Timeout with Ajaxterm

Hi Everyone, I have a similar question to this: http://stackoverflow.com/questions/1287064/php-session-timeout-callback Basically, I want to run some code once a user has been inactive for a certain amount of time. However my case is a little more tricky than the above question. This is because I am using Ajaxterm: http://antony.lesuis...