python

how to enable custom string in django.po for Localization in django

this is the demo.rar file. 1 . i use this code to create a zh-CN : django-admin.py makemessages -l zh-CN 2 . i add some string to django.po : msgid "zjm1126" msgstr "哈哈哈!!!" 3 . and then compile it : django-admin.py compilemessages but i don't find it become chinese words so why ? thanks ...

How can I ensure good test-coverage of my big Python proejct

I have a very large python project with a very large test suite. Recently we have decided to quantify the quality of our test-coverage. I'm looking for a tool to automate the test coverage report generation. Ideally I'd like to have attractive, easy to read reports but I'd settle for less attractive reports if I could make it work quic...

"Annotating" querysets with model function returns

Basically I want to do something similar to annotating a queryset but with a call on a function in the model attached to the response. Currently I have something like: objs = WebSvc.objects.all().order_by('content_type', 'id') for o in objs: o.state = o.cast().get_state() where get_state() is a function in the model that calls an...

Problems with sending commands over pySerial

Hi. I'm trying to talk to a home made card over a serial port, and is therefor using pySerial. In Hyperterminal, everything works fine. I can write: $ audio on and the audio is enabled, but if I use ser = serial.Serial("COM1", 38400) ser.write("audio on\r\n") nothing happens. I can read incoming data however, so it's not something...

Should I use Python 32bit or Python 64bit

I have a win7 64bit installation. Must I use Python 64bit? What are the differences between the 32bit and 64bit Python versions anyway? Do different Python packages (such as south, django, mysqldb etc) support only 32bit\64bit? ...

FancyURLopener hangs when not passing a proxy or passing an ISA one

Hi, I'm trying to create a script to automate some actions involving chained GET and POST HTTP requests. I'm using Python 3.1 on a Windows XP SP3 machine, and I need to interact to a web server located on our intranet (so no proxy should be involved). Mind that I'm quite new to Python so coding class inheritance, overriding and such is...

How can I use common code in python?

I'm currently maintaining two of my own applications. They both share some common aspects, and as a result, share some code. So far, I've just copied the modules from one project to the other, but now it's becoming a maintenance issue. I'd rather have the common code in one place, outside of both of the projects, which they can both impo...

How to write custom python logging handler?

How to write custom console log function to output only on the console window log messages on a single line (not append) until the first regular log record. progress = ProgressConsoleHandler() console = logging.StreamHandler() logger = logging.getLogger('test') logger.setLevel(logging.DEBUG) logger.addHandler(console) logger.addH...

How to declare a C struct with a pointer to array in ctypes?

Hi there, I read the official ctypes tutorial and also searched SO, but I could not find a way to declare this kind of structure with ctypes. This structure is returned by one of the functions I write an Python interface for. typedef struct{ int i; float *b1; float (*w1)[]; }foo; This is what I have so far: class foo(Str...

Entity exists, empty template is returned

I got the following very basic template: <html> <head> </head> <body> <div> <!-- Using "for" to iterate through potential pages would prevent getting empty strings even if only one page is returned because the "page" is not equal the query, it is a subcomponent of the query --> <div>{{ page.name }}</div> <div>{{ page.leftText }}</div> ...

Python tar generation question

I'm creating a tar file from a directory as such /home/user/bla/mydir/ Now I want to create a tar.gz file which starts from mydir/, not having directory list of the archieve content listing starting from /home/user/bla/mydir/. How can this be done? Here is my original one: tar = tarfile.open("/home/user/mytar.tar.gz", "w:gz") tar...

why does python os.path.isfile seem to ignore certain file types?

Hi, simple script on a unix system (Mac) which seems to only return certain files True. Can't figure out why: workdir = '/Volumes/place/sub place' def myFunc(bla, dir, flist): for f in flist: print f, os.path.isfile(f) os.path.walk(workdir,myFunc,None) Returns: tests.py False utils.py False utils.pyc False writeXmlFor...

Convert HTTP Proxy to HTTPS Proxy in Twisted

Hey, Recently I have been playing around with the HTTP Proxy in twisted. After much trial and error I think I finally I have something working. What I want to know though, is how, if it is possible, do I expand this proxy to also be able to handle HTTPS pages? Here is what I've got so far: from twisted.internet import reactor from twist...

Alternative to Natlink

I need to create a speech recognition program where a user can speak into a microphone and have the program continuously recognize the speech event and return a results object with audio, time stats, the transcription and more along those lines. Like the ResObj in Natlink. Unfortunately, due to system incompatibilities, Natlink is not an...

urllib2 and cookielib thread safety

As far as I've been able to tell cookielib isnt thread safe; but then again the post stating so is five years old, so it might be wrong. Nevertheless, I've been wondering - If I spawn a class like this: class Acc: jar = cookielib.CookieJar() cookie = urllib2.HTTPCookieProcessor(jar) opener = urllib2.build_opener(coo...

Python 3.1 Installation missing Tkinter on OS 10.6.4

Has anyone else had this problem? I have re-installed twice with the same result. The pre-install of 2.6 on the Mac had a lib-tk folder with the correct modules. Nothing like this is being created for 3.1. There is a Tkinter folder but it contains only a few obscure modules. Importing _tkinter and tkinter works but not Tkinter and all of...

How to select an item in a gtk.IconView (Python)

In a gtk.IconView I can use get_selected_items() to find the paths of the items a user selected in the view. I'm now looking for the corresponding method to set the selection of an IconView. But I can't find any!? What am I missing? ...

Implementing the decorator pattern in Python

I want to implement the decorator pattern in Python, and I wondered if there is a way to write a decorator that just implements the function it wants to modify, without writing boiler-plate for all the functions that are just forwarded to the decorated object. Like so: class foo(object): def f1(self): print "original f1" ...

datetime issue with xlrd & xlwt python libs

I'm trying to write some dates from one excel spreadsheet to another. Currently, I'm getting a representation in excel that isn't quite what I want such as this: "40299.2501157407" I can get the date to print out fine to the console, however it doesn't seem to work right writing to the excel spreadsheet -- the data must be a date type i...

Extension modules and common routines in Python/C API

Hello! I'm writing wrapper for C library. This library consist of several parts. And i want split my extension package into different extension modules. I think, this is the right way ;-) But, there are some common parts that exist in extension package, get_library_version, Error, and so on. I've decided to create additional module, nam...