python

How do i use perspective projection in this library

i found a library called pyeuclid and it seems to do what i want in respect to 3D math. it contins a 3D vector class and a 4X4 matrix class capable of transformations like rotate,translate and scale. matrix creation is simple, simply pass along the arguments and the matrix is created. >>> m = Matrix4() >>> m.translate(50,50,50) Matri...

String arguments in python multiprocessing

I'm trying to pass a string argument to a target function in a process. Somehow, the string is interpreted as a list of as many arguments as there are characters. This is the code: import multiprocessing def write(s): print s write('hello') p = multiprocessing.Process(target=write, args=('hello')) p.start() I get this output:...

Which is the most pythonic: installing python modules via a package manager ( macports, apt) or via pip/easy_install/setuptools

Usually I tend to install things via the package manager, for unixy stuff. However, when I programmed a lot of perl, I would use CPAN, newer versions and all that. In general, I used to install system stuff via package manager, and language stuff via it's own package manager ( gem/easy_install|pip/cpan) Now using python primarily, I ...

Regular Expression for HTML artifacts

Hi, I some text with HTML artifacts where the < and > of tags got dropped, so now I need something that will match a small p followed by a capital letter, like pThe next day they.... And I also need something that will catch the trailing /p which is easier. These need to be stripped, i.e. replaced with "" in python. What RE would I ...

coverage.py: exclude files

How do I exclude entire files from coverage.py reports? According to the documentation you can exclude code by matching lines. I want to exclude entire files, so that the reports don't include 3rd party libraries. Am I missing something? Can it be done? ...

python - get a key press from the linux command line without having to press enter

I'm writing a command line python programme on linux. I want to ask the user to press a single key, and then it should return that key press. I don't want them to have to press enter, so I can't use the builtin raw_input() method. ...

How to send a dictionary to a function that accepts **kwargs?

I have a function that accepts wildcard keyword parameters: def func(**kargs): doA doB How do I send it a dictionary? ...

Embedded objects in MS Office documents using Python?

How could I create embedded objects in an MS office document using Python? I don't need anything fancy, just what one used to do in the first version of OLE: doing a copy-paste from my application into e.g. MS Word should give me an object embedded in the Word document, which I can then double-click to open a copy of my application a...

"undefined symbol: TLSv1_method" error when import psycopg2

I installed psycopg2 by "easy_install psycopg2" on CentOS 5.3, no error was reported, but when I tried "import psycopg2", I got : exceptions.ImportError: /usr/lib/python2.4/site-packages/psycopg2-2.0.9-py2.4-linux-i686.egg/psycopg2/_psycopg.so: undefined symbol: TLSv1_method What might cause the problem? ...

Optparse library - callback action while storing arg

My code: def main(): usage = "usage: %prog [options] arg" parser = OptionParser(usage) parser.add_option("-p", "--pending", action="callback", callback=pending, type="string", dest="test", help="View Pending Jobs") (options, args) = parser.parse_args() if x == 0: print usage, " (-h or --help for help)" print...

What is a good example of an __eq__ method for a collection class?

I'm working on a collection class that I want to create an __eq__ method for. It's turning out to be more nuanced than I thought it would be and I've noticed several intricacies as far as how the built-in collection classes work. What would really help me the most is a good example. Are there any pure Python implementations of an __eq...

How can I get the (x,y) values of the line that is ploted by a contour plot (matplotlib)?

Hello everybody, Is there an easy way to get the (x,y) values of a contour line that was plotted like this: import matplotlib.pyplot as plt x = [1,2,3,4] y = [1,2,3,4] m = [[15,14,13,12],[14,12,10,8],[13,10,7,4],[12,8,4,0]] cs = plt.contour(x,y,m, [9.5]) plt.show() Cheers, Philipp ...

Equivalent of GetCursorPos() in Mac's Carbon

Background We're porting our PythonOgre-based games to Mac, and the publishers demand ability for mouse to leave the window. On Windows, we're going around OIS (Object-oriented Input System) for the purposes of mouse control; that is, we don't let OIS keep the mouse captured inside window borders, and then track the mouse cursor in scree...

Histogram in matplotlib gets cropped at top

I have a Python program that generates a histogram using matplotlib. The problem is that the images that are generated sometimes get cropped at the top. First, here's the relevant code excerpt, where plt is matplotlib.pyplot and fig is matplotlib.figure: plt.hist(grades, bins=min(20, maxScore), range=(0,maxScore), figure=fig.Figure(fi...

Python - Overwriting __getattribute__ for an instance?

Hi! This one seems a bit tricky to me. Sometime ago i already managed to overwrite an instance's method with something like: def my_method(self, attr): pass instancemethod = type(self.method_to_overwrite) self.method_to_overwrite = instancemethod(my_method, self, self.__class__) which worked very well for me; but now I'm trying t...

Playing sounds with python and changing their tone during playback?

Is there a way to do this? Also, I need this to work with pygame, since I want audio in my game. I'm asking this because I didn't see any tone change function in pygame.. Anyone knows? Update: I need to do something like the noise of a car accelerating. I don't really know if it is timbre or tone. ...

Python Reverse Generator

Hi, I'm looking for a way to reverse a generator object. I know how to reverse sequences: foo = imap(seq.__getitem__, xrange(len(seq)-1, -1, -1)) But is something similar possible with a generator as the input and a reversed generator as the output (len(seq) stays the same, so the value from the original sequence can be used)? ...

Structuring a program. Classes and functions in Python

I'm writing a program that uses genetic techniques to evolve equations. I want to be able to submit the function 'mainfunc' to the Parallel Python 'submit' function. The function 'mainfunc' calls two or three methods defined in the Utility class. They instantiate other classes and call various methods. I think what I want is all of it in...

problem handling db conection on daemonize threads...

Just for the record, i just started programing on python, and this is the first time i try to do a daemon. I have a problem handling DB connections in a daemon i've been working on, the first thing i do, is connect to my postgres db with: try: psycopg2.apilevel = '2.0' psycopg2.threadsafety = 3 cnx = psycopg2.connect( "host='192....

How do you make a shared network file read-only using Python?

Using Python, what's the correct way to set a file to be read-only when the file is located on a network share (being served from a Windows 2003 Server)? I'm running Python 2.6.2 in OS X (10.6.1). The following code throws an exception (as expected) when path is local, but os.chmod appears to have no effect when path points to a Window...