python

How to pass a specific argument to a decorator in python

I want to write a python function decorator that tests that certain arguments to a function pass some criterion. For eg, Suppose I want to test that some arguments are always even, then I want to be able to do something like this (not valid python code) def ensure_even( n ) : def decorator( function ) : @functools.wraps( functio...

What kind of regex would I use to match this?

I have several strings which look like the following: <some_text> TAG[<some_text>@11.22.33.44] <some_text> I want to get the ip_address and only the ip_address from this line. (For the sake of this example, assume that the ip address will always be in this format xx.xx.xx.xx) Edit: I'm afraid I wasn't clear. The strings will look s...

WxPython: deriving wx.ListItem but wx.ListCtrl only returns old class

Hello people, I've got a small issue with derived classes, namely wx.ListItem with wx.ListCtrl. I succesfully derived wx.ListItem as a MediaItem, the code is not finished but you get the point: class MediaItem(wx.ListItem): def __init__ (self, fullname): wx.ListItem.__init__(self) self.fullname = fullname s...

to get number of frames between a time range?

I want to find the number of frames in wav file between certain time range that is generally using the function wave.getnframes we can get the number of frames in the complete wave file but here i want to know how to find the number frames between a certain time range such number of frames between 5.43 sec to 5.81 secs.. how can we do t...

Mensagem no console do servidor Python (wsgiref)

How do I hide the message automatically sent by a server for Python console? On a server that uses WSGIREF. like this: practivate.adobe.com - - [30/Jun/2010 15:18:13] "POST /aguia.html HTTP/1.1" 200 4 practivate.adobe.com - - [30/Jun/2010 15:18:14] "POST /aguia.html HTTP/1.1" 200 4 practivate.adobe.com - - [30/Jun/2010 15:18:17] "POST /...

FAPWS: Form with File Upload and parameters. Help parse the raw input?

I have a form that is multi-part for file upload, but it also has some other parameters like username, password, etc. Here's what the HTML form looks like: http://pastebin.com/AjmGsQBu And here's my python code to handle it: http://pastebin.com/kj1PBYmH I've verified with Charles that all the parameters are being submitted, they're ju...

Splitting items in a list into two and appending one of them to another list.

Hey all. Trying to get a little more efficient with lists in Python but I cant seem to figure out if I can do what I want or even if it is worth figuring out. stream is a list. Each item in the list is something like : 10,123400FFFE001DB9AA I am trying to get to the second part of each item after the comma so I run through the list sp...

python refactoring (similar methods in class)

Python refactoring Both the add and sub are very similar. How does one re-factor code like this? The logic is basically inverse of each other. class point(object): def __init__( self, x, y ): self.x, self.y = x, y def add( self, p ): x = self.x + p.x y = self.y + p.y return point(...

PyV8 Install Problems (Cannot find boost)

I am attempting to install PyV8 (http://code.google.com/p/pyv8/) using: python setup.py install However, the build fails with the following: louis@louis-desktop:~/Downloads/PyV8-0.9$ python setup.py install running install running build running build_py running build_ext building '_PyV8' extension gcc -pthread -fno-strict-aliasing -D...

Any way to improve this python function?

def __number(): # This line returns the number of the latest created object # as a "Factura" object in format "n/year" last = Factura.objects.filter(f_type__exact=False).latest('number') # We convert it into a string and split it to get only the first number spl = str(last).split('/')[0] # Convert it into intege...

Python Class scope & lists

I'm still fairly new to Python, and my OO experience comes from Java. So I have some code I've written in Python that's acting very unusual to me, given the following code: class MyClass(): mylist = [] mynum = 0 def __init__(self): # populate list with some value. self.mylist.app...

How can I change name of option in django select box

I got 2 models class Category(models.Model): name = models.CharField(max_length=30, unique=True) class Post(models.Model): ...... category = models.ForeginKey(Category) ........ And when I create a form, in select box i got options "Category object", but i would like to display name of category, i am sure it's basic,...

Expose __main__

Hi everybody, is this legal in python?. Seems to work ... Thanks # with these lines you not need global variables anymore if __name__ == '__main__': import __main__ as main else: main = __import__(os.path.basename(os.path.splitext(__file__))) var_in_main = 0 # now any var is a global var, you can access any var from every...

Localhost bottleneck with python sockets

I'm sending a very large string from one application to another on localhost using sockets in python. Small strings move instantly, but large strings seem to take a while longer (I say large, but I'm talking maybe a MB or two at the very most). Enough that I have to sit and wait a few seconds after I do something in one app before it sh...

File upload error on google app engine

I'm trying to upload a file with curl, but I keep running into this one error. AttributeError: 'unicode' object has no attribute 'file' I'm on OSX, and the curl command im using looks like this: curl -d "attach=@`pwd`/output.txt" http://localhost:8081 The app engine code looks like this which is taken from the image share example a...

Re-assemble email messages encoded in 'message/partial' with Python

Is there a way to reassemble in Python email messages that are encoded with Content-Type: message/partial (i.e. section '7.3.2. The Message/Partial subtype' of RFC 1521)? In particular, given a set of emails, how can one merge them back into an original? i.e. emails = [...] # a list of `email`. reassembled_email = merge_emails(emails...

How do I pipe the output of file to a variable in Python?

How do I pipe the output of file to a variable in Python? Is it possible? Say to pipe the output of netstat to a variable x in Python? ...

Python and plone output of 'None'

I have a python script in Plone: query = 'hello me' print context.run_blast_query(query) return printed I have a external script: def print_query(x): return x The plone script should call the external script and print 'hello me' but instead prints 'none'. I know the function names dont match it is parsed via a external method. ...

'METHODNAME' as Client method versus irc_'METHODNAME' in twisted

Looking at twisted.words.protocols.irc.IRCClient, it seems to me like there are some strangely redundant methods. For instance, there is a method 'privmsg' but also a method 'irc_PRIVMSG' As another example consider 'join' and 'irc_JOIN' What I want to know is why the redundancy, those are just two examples of many. Are the two differe...

Open a file in a function and write to it

I created the function below: def print_form(x): f = open('/home/rv/Plone/Zope-2.10.11-final-py2.4/Extensions/test.fasta', 'w') f.write(str(x)) f.close() return x The function returns and prints, but doesnt write it to a file or creates it? EDIT I editied the above code the so the file is created in a specific loca...