python

Preventing grouping of Python socket.send data from Queue

I am currently making a network layer built that creates binary messages and then sends them to the appropriate network interface (this could be Ethernet, WiFi, Bluetooth, etc). In working on the TCP module, I'm using Python's socket module and everything works great except for when I try to send a series of messages quickly (such as a l...

Python: Convert Unicode to ASCII without errors

html = urllib.urlopen(link).read() html.encode("utf8","ignore") self.response.out.write(html) Traceback (most recent call last): File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 507, in __call__ ha...

Integrating SQLAlchemy's ORM with existing classes in pylons.

I have a class in my existing python project, User, that I would like to map to tables. But I'm not sure what the best way to do this is? Does this mean I can remove: class User: pass from my model/__ init __.py? Or should I leave that in there, and have something like: from project.model.user import User class User: pass ...

Better looping, for string manipulation (python)

If i have this code s = 'abcdefghi' for grp in (s[:3],s[3:6],s[6:]): print "'%s'"%(grp) total = calc_total(grp) if (grp==s[:3]): # more code than this p = total + random_value x1 = my_function(p) if (grp==s[3:6]): # more code than this p = total + x1 x2 = my_function(p) ...

Designing to easily migrate to Google App Engine

I am going to start designing a web app shortly, and while I have lots of experience doing it in the SQL world, I have no idea what I need to take into consideration for doing so with the goal of migrating to GAE in the very near future. Alternatively, I could design the app for GAE from the start, and so in that case, what are the diff...

Decorating python class methods, how do I pass the instance to the decorator?

This is python 2.5, it's GAE too not that it matters. I have the following code, I'm decorating the foo() method in bar, using the dec_check class as a decorator. class dec_check(object): def __init__(self, f): self.func = f def __call__(self): print 'In auth_check.__init__()' self.func() class bar(object): @dec...

Jinja2 in Google App Engine

Hello, I have started using Jinja2 as my templating engine on Google App Engine (in Python). My question is this: Will bytecode caching work in production? It is working very well on the development server, but I read somewhere that bytecode caching depends on the marshal module, which is not supported in App Engine. This answer to a d...

haskell vs python typing

I am looking for example where things in python would be easier to program just because it is dynamically typed? I want to compare it with Haskell type system because its static typing doesn't get in the way like c# or java. Can I program in Haskell as I can in python without static typing being a hindrance? PS: I am a python user an...

What's the Python2.5 equivalent of Python2.6 translate with None as first param?

In Python 2.6, I can run the following fine to strip out chars like -() '(123) 456-7890'.translate(None, '-(), ') Python2.5 translate does not accept None, how can I do the above in 2.5? ...

Python interface for outputting MIDI files or text that's readable by audio programs

I am looking for a python package or library that will allow me to programmatically output a file format (e.g. MIDI) that can be read by audio/sound processing programs, like LogicPro or iDrum. What are the best options for this? thanks very much. ...

merging Python dictionaries

Hi everyone, I am trying to merge the following python dictionaries as follow: dict1= {'paul':100, 'john':80, 'ted':34, 'herve':10} dict2 = {'paul':'a', 'john':'b', 'ted':'c', 'peter':'d'} output = {'paul':[100,'a'], 'john':[80, 'b'], 'ted':[34,'c'], 'peter':[None, 'd'], 'herve':[10, None]} Any tip about an efficient way to do this?...

Using Python, how do I read and extract data from a binary data file with multiple variable-length records?

Using Python (3.1 or 2.6), I'm trying to read data from binary data files produced by a GPS receiver. Data for each hour is stored in a separate file, each of which is about 18 MiB. The data files have multiple variable-length records, but for now I need to extract data from just one of the records. I've got as far as being able to deco...

Where can i get exercises for 'Dive into Python 3'?

I'm learning python with 'Dive Into Python 3' and It's very hard to remember everything, without writing something, but there are no exercises in this book. So I ask here, where can i find them to remember everything better. ...

Python Boto S3 to work with Custom Domains in Amazon S3

How do I use the Python Boto library with S3 where the URL's it generate will be my CNAME'd subdomain to the Amazon S3 Server. By default it uses the default format BUCKETNAME.s3.amazonaws.com but S3 supports custom domain aliasing using CNAME (so you can have custom.domain.com -> CNAME -> custom.domain.com.s3.amazonaws.com where "cust...

Python: split a full name "First Last", "First Middle Last," etc ... into separate variables?

I'm looking for the best way to write a function that takes a string in the form: "First" "First Last" "First Middle Last" "First M. Last" "First Second Third Last" And can return a python a list with each of the values separated. Thanks. ...

Can you go to a line with the file operations in python?

I'm parsing a file and need to keep track of where I am in the file... let's say I have file test.txt and I'm doing a while loop that reads in data constantly as each line is written to the file. In case of a crash I'm marking my position in another file with the tell() method of the file. Is there a way to mark the line and be able to g...

CAC Client Application Authentication in Python

I am building a python application to pull data from a website. The application has to authenticate(HTTPS/SSL) with a CAC card and pin in order to make requests. Am I correct in my assumptions that you can't retrieve the private key from a CAC card, and am therefore stuck using a PKCS #11 Wrapper like PyKCS? Any tips or resources for g...

Can a Python Decorator of an Instance Method Access the Class?

Hi I have something roughly like the following. Basically I need to access the class of an instance method from a decorator used upon the instance method in its definition. def decorator(view): # do something that requires view's class print view.im_class return view class ModelA(object): @decorator def a_method(se...

Is there a way to specify a fixed (or variable) number of elements for lxml in Python

There must be an easier way to do this. I need some text from a large number of html documents. In my tests the most reliable way to find it is to look for specific word in the text_content of the div elements. If I want to inspect a specific element above the one that has my text I have been enumerating my list of div elements and us...

on click event in wx.Panel?

Hello, how can I click on a wx.Panel and that changes its color? What is the name of the event. (I want to do a similar thing as Firefox Extras) Thanks in advance! :) ...