python

Python equivalent of PHPs __call() magic method?

In PHP, I can do something like this: class MyClass { function __call($name, $args) { print('you tried to call a the method named: ' . $name); } } $Obj = new MyClass(); $Obj->nonexistant_method(); // prints "you tried to call a method named: nonexistant_method" This would be handy to be able to do in Python for a project I...

What is the difference between LIST.append(1) and LIST = LIST + [1] (Python)

When I execute (I'm using the interactive shell) these statements I get this: L=[1,2,3] K=L L.append(4) L [1,2,3,4] K [1,2,3,4] But when I do exactly the same thing replacing L.append(4) with L=L+[4] I get: L [1,2,3,4] K [1,2,3] Is this some sort of reference thing? Why does this happen? Another funny thing I noticed is that L+=...

find time difference in seconds as an integer with python

I need to find the time difference in seconds with python. I know I can get the difference like this: from datetime import datetime now = datetime.now() .... .... .... later = datetime.now() difference = later-now how do I get difference in total seconds? ...

what is the max size of TextProperty on google app engine .

class JsTree_JsonData(db.Model): JsonData=db.TextProperty() i can;t find what is the TextProperty did you know ? thanks ...

Why do I get inconsistent exceptions on Python?

I encountered a very strange behavior in Python, a behavior that is not consistent. ... except IOError as msg: sys.exit("###ERROR IOError: %s" % (msg)) Usually this would get me a message like: ###ERROR IOError: [Errno 13] Permission denied: 'filename' In same cases the above code is giving me a tuple instead of a proper error ...

Search by a property of a reference

I have the following models: class Station(db.Model): code = db.StringProperty(required=True) name = db.StringProperty(required=True) class Schedule(db.Model): tripCode = db.StringProperty(required=True) station = db.ReferenceProperty(Station, required=True) arrivalTime = db.TimeProperty(required=True) depar...

Is Tornado really non-blocking?

Tornado advertises itself as "a relatively simple, non-blocking web server framework" and was designed to solve the C10k problem. However, looking at their database wrapper, which wraps MySQLdb, I came across the following piece of code: def _execute(self, cursor, query, parameters): try: return cursor.execute(query, paramet...

Proper indendation with backslash line continuations in python-mode.el

I like to use python-mode.el and (gnu) emacs for editing my python files. If I use parentheses for multiline continuations, indentation works as I expect. For example, foo_long_long_long_long = ( bar_long_long_long_long[ (x_long_long_long_long == X) & (y_long_long_long_long == Y)]) is just the way I like it. On ...

What is necessary to use Win32 extensions with Portable Python

I installed Portable Python in an USB drive and it is working but I cannot make it import Win32 extensions. ...

how do I set a field with a duplicate name of another field in mechanize?

I am trying to submit a form with 2 fields with the same name but different type. I can identify the correct field I want by the field type or the number. Whats the best way of setting the correct field without iterating through all the fields? ...

Module name redefines built-in

I'm making a game in Python, and it makes sense to have one of my modules named 'map'. My preferred way of importing is to do this: from mygame import map As pylint is telling me, however, this is redefining a built-in. What's the common way of dealing with this? Here are the choices I can come up with: 1) Ignore the pylint warnin...

Writing a parser for regular expressions

Even after years of programming, I'm ashamed to say that I've never really fully grasped regular expressions. In general, when a problem calls for a regex, I can usually (after a bunch of referring to syntax) come up with an appropriate one, but it's a technique that I find myself using increasingly often. So, to teach myself and under...

Design pattern for multiple consumers and a single data source.

I am designing a web interface to a certain hardware appliance that provides its own custom API. Said web interface can manage multiple appliances at once. The data is retrieved from appliance through polling with the custom API so it'd be preferable to make it asynchronous. The most obvious thing is to have a poller thread that polls ...

Trouble with variable. [Python]

I have this variable on the beginning of the code: enterActive = False and then, in the end of it, I have this part: def onKeyboardEvent(event): if event.KeyID == 113: # F2 doLogin() enterActive = True if event.KeyID == 13: # ENTER if enterActive == True: m_lclick() return...

Importing SPSS dataset into Python

Hi, Is there any way to import SPSS dataset into Python, preferably NumPy recarray format? I have looked around but could not find any answer. Joon ...

Break a text file into chunks based on line like the string split operation?

I have text report files I need to "split()" like strings are split up into arrays. So the file is like: BOBO:12341234123412341234 1234123412341234123412341 123412341234 BOBO:12349087609812340-98 43690871234509875 45 BOBO:32498714235908713248 0987235 And I want to create 3 sub-files out of that splitting on lines that begin with "^...

sending file throught xml::rpc

How can i send a file through xml::rpc from xml-rpc client to xml-rpc server i use 2 languages for the client and the server (c# and python ) any ideas ? ...

Help with if statement

I'm trying this part of my script and it work perfectly if win32gui.GetCursorInfo()[1] == 65567: but when I'm trying to add this win32gui.GetCursorInfo()[2] == categoriesScreenPos[1]: it stop working... why? The categoriesScreenPos[1] is the same value (17,242) of the position of the cursor, but the if doesn't work... Full if: i...

Python, ctypes and mmap

I am wondering if it is possible for the ctypes package to interface with mmap. Currently, my module allocates a buffer (with create_string_buffer) and then passes that using byref to my libraries mylib.read function. This, as the name suggests, reads data into the buffer. I then call file.write(buf.raw) to write the data to disk. My be...

Regular Expressions: Search in list

I want to filter strings in a list based on a regular expression. Is there something better than [x for x in list if r.match(x)] ? ...