python

Tips on Python MIL-STD-1553

Has anyone ever worked with MIL-STD-1553 in Python? How did you do it? ...

Python global variable insanity

You have three files: main.py, second.py, and common.py common.py #!/usr/bin/python GLOBAL_ONE = "Frank" main.py #!/usr/bin/python from common import * from second import secondTest if __name__ == "__main__": global GLOBAL_ONE print GLOBAL_ONE #Prints "Frank" GLOBAL_ONE = "Bob" print GLOBAL_ONE #Prints "Bob" se...

Why do I get TypeError: get() takes exactly 2 arguments (1 given)? Google App Engine

I have been trying and trying for several hours now and there must be an easy way to retreive the url. I thought this was the way: #from data.models import Program import basehandler class ProgramViewHandler(basehandler.BaseHandler): def get(self,slug): # query = Program.all() # query.filter('slug =', fslug) ...

How to lazily evaluate ORM call after fixtures are loaded into db in Django?

I've got a module pagetypes.py that extracts a couple of constants (I shouldn't really use word constant here) from the db for later reuse: def _get_page_type_(type): return PageType.objects.get(type=type) PAGE_TYPE_MAIN = _get_page_type_('Main') PAGE_TYPE_OTHER = _get_page_type_('Other') then somewhere in views I do: import pag...

library for text rendering that supports text-on-path

I need a good, reliable library or toolchain for programatically rendering text to png, with different sizes, fonts, weights, etc. It also needs to be able to render text in an arc or to a path. I would like it to be fast, because I'd be running it as on a server. I've tried using SVG and librsvg, but that doesn't render <textPath> elem...

Python: deepcopy(list) vs new_list = old_list[:]

I'm doing exercise #9 from http://openbookproject.net/thinkcs/python/english2e/ch09.html and have ran into something that doesn't make sense. The exercise suggests using copy.deepcopy() to make my task easier but I don't see how it could. def add_row(matrix): """ >>> m = [[0, 0], [0, 0]] >>> add_row(m) [[0, ...

Drawing semi-transparent polygons in PIL

How do you draw semi-transparent polygons using the Python Imaging Library? ...

Parsing Java Class From Perl or Python

I want to get a .java file, recognize the first class in the file and getting information about annotations, methods and attributes from this class. Is there any module in both languages that already does that? I could build up a simple regexp to do it also, but I don't known how to recognize in the regexp the braces indicating the end ...

How do I "print" something to the console in pylons?

paster serve --reload development.ini ..for debug = true THis is what I do to load a development server for Pylons. However, when I do: print "hello world" THis message doesn't print out in the console. In Django, it does. ...

How to fix ImportError in matplotlib

I compiled matplotlib on a mac running snow leopard only to find that when I import matplotlib.pyplot I get the following error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py", line 6, in <module> fro...

Confirm that Python 2.6 ftplib does not support Unicode file names? Alternatives?

Can someone confirm that Python 2.6 ftplib does NOT support Unicode file names? Or must Unicode file names be specially encoded in order to be used with the ftplib module? The following email exchange seems to support my conclusion that the ftplib module only supports ASCII file names. Should ftplib use UTF-8 instead of latin-1 encodin...

How do I count the number of occurrences of a list of items in another .txt file?

I have a list of words and I want to find how many times they occur in a .txt file. The word list is something like as follows: wordlist = ['cup', 'bike', 'run'] I want to be able to not only pick up these words, but also things like CUP, biker, running, Cups, etc. So I think I need a regular expression. Here is what I was thinking...

parsing a line of text to get a specific number

I have a line of text in the form " some spaces variable = 7 = '0x07' some more data" I want to parse it and get the number 7 from "some variable = 7". How can this be done in python? ...

Is there an Objective-C equivalent to Python urllib and urllib2?

Are there any equivalents in objective-c to the following python urllib2 functions? Request, urlopen, HTTPError, HTTPCookieProRequest, urlopen, HTTPError, HTTPCookieProcessor Also, how would I able to to this and change the method from "get" to "post"? ...

How to improve performance through Python multithreading

I'm new to Python and multithreading, so please bear with me. I'm writing a script to process domains in a list through Web of Trust, a service that ranks websites from 1-100 on a scale of "trustworthiness", and write them to a CSV. Unfortunately Web of Trust's servers can take quite a while to respond, and processing 100k domains can t...

Python, subclassing immutable types

I've the following class: class MySet(set): def __init__(self, arg=None): if isinstance(arg, basestring): arg = arg.split() set.__init__(self, arg) This works as expected (initialising the set with the words of the string rather than the letters). However when I want to do the same with the immutable ...

Byte precision of value in Python?

I have a hash function in Python. It returns a value. How do I see the byte-size of this return value? I want to know if it is 4-bytes or 8 or what. Reason: I want to make sure that the min value is 0 and the max value is 2**32, otherwise my calculations are incorrect. I want to make sure that packing it to a I struct (unsigned int) ...

How do I send an email from a non-gmail account using the appengine

I have successfully sent an email using the Google App Engine. However the only email address I can get to work is the gmail address I have listed as the admin of the site. I'm running the app on my own domain (bought and maintained using Google Apps). I would like to send the email from my own domain. Here's the code (or something simil...

Django to do its own NTLM Authentication (HTTP Headers & all)

I'm considering moving from Apache to Lighttpd for an internal web application, written with python. The problem is that I'm relying on libapache2-mod-auth-ntlm-winbind ... which doesn't actually seem to be a well support & updated package (though that could be because it really does work well). I'm looking for suggestions and hints ab...

Check if some game is currently running and on top.

I am creating a keybind program for one game. So far it works perfectly but I constantly minimize this game to IM or do something else. So.. How do I make my program work when I got this game on top and when the game is minimized the program shouldn't work. ...