python

How can I use Perl libraries from Python?

Dear All, I have written a bunch of Perl libraries (actually Perl classes) and I want to use some of them in my Python application. Is there a natural way to do this without using SWIG or writing Perl API for Python. I am asking for a similar way of PHP's Perl interface. If there is no such kind of work for Perl in Python. What is the e...

Auto __repr__ method

I want to have simple representation of any class, like { property = value }, is there auto __repr__? ...

Efficient way of Solving Cryptarithms

Hi i came across this puzzle which is a subset of famous kind of word and numbers based puzzles called Cryptarithms. Say you have an expression as S E N D + M O R E = M O N E Y Now the interesting part there is that, each alphabet is representing a unique digit from 0-9. I wanted to write a generalized solver, but i ended up writing ...

Binary array in python

How to create big array in python, how efficient creating that in C/C++: byte *data = (byte*)memalloc(10000); or byte *data = new byte[10000]; in python...? ...

How do I use the wx.lib.docview package?

I'm currently working on a simple wxPython app that's essentially document based. So far I've been manually implementing the usual open/save/undo/redo etc etc stuff. It occurred to me that wxPython must have something to help me out and after a bit of searching revealed the docview package. At this point though I'm just not quite sure...

Why does this pyd file not import on some computers?

My python project has a C++ component which is compiled and distributed as a .pyd file inside a Python egg. I've noticed that it seems to be incompatible with only some of our our brand new 64 bit Windows servers. We have 4 (allegedly) identically provisioned machines - each of them runs Windows 2003 server 64 bit edition, but 2 of these...

dispatcher python

hy all, I have the following "wrong" dispatcher: def _load_methods(self): import os, sys, glob sys.path.insert(0, 'modules\commands') for c in glob.glob('modules\commands\Command*.py'): if os.path.isdir(c): continue c = os.path.splitext(c)[0] parts = c.split(os.path.sep ) module, name = '.'.join( parts ), parts[-1:] modu...

can a method call be chained to the 'set()' built-in? (and why not?)

If I try: mi_list = ['three', 'small', 'words'] mi_set = set(mi_list) mi_set.remove('small') print mi_set I get: set(['three', 'words']) which is what I expect. Whereas If I try: mi_list = ['three', 'small', 'words'] mi_set = set(mi_list).remove('small') print mi_set I get: None Why? I suspect there's a clue in that if ...

Parse shell file output with Python

I have a file with data. The file is the output generated from a shell scripting file: |a |869 | |b |835 | |c |0 | |d |0 | |e |34 | |f |3337 How can I get a = 869 from thi...

Split array into smaller arrays.

I am looking for a way to easily split a python array in half. So that if I have an array: A = [0,1,2,3,4,5] I would be able to get: B = [0,1,2] C = [3,4,5] ...

Has anyone here tried using the iSeries Python port?

I found http://www.iseriespython.com/, which is a version of Python for the iSeries apparently including some system specific data access classes. I am keen to try this out, but will have to get approval at work to do so. My questions are: Does the port work well, or are there limits to what the interpreter can handle compared with stan...

Is it safe to rely on condition evaluation order in if statements?

Is it bad practice to use the following format when my_var can be None? if my_var and 'something' in my_var: #do something *The issue is that 'something' in my_var will throw a TypeError if my_var is None.* Or should I use: if my_var: if 'something' in my_var: #do something or try: if 'something' in my_var: ...

Can I compile numpy & scipy as eggs for free on Windows32?

I've been asked to provide Numpy & Scipy as python egg files. Unfortunately Numpy and Scipy do not make official releases of their product in .egg form for a Win32 platform - that means if I want eggs then I have to compile them myself. At the moment my employer provides Visual Studio.Net 2003, which will compile no version of Numpy lat...

"Slicing" in Python Expressions documentation

I don't understand the following part of the Python docs: http://docs.python.org/reference/expressions.html#slicings Is this referring to list slicing ( x=[1,2,3,4]; x[0:2] )..? Particularly the parts referring to ellipsis.. slice_item ::= expression | proper_slice | ellipsis The conversion of a slice item that is an expre...

How to work with unicode in Python

I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' and am starting to lean towards creating my own dictionary for the entities and symbols and running a replace on the string. I am considering this because I want to automate the process and ther...

Strip html from strings in python

from mechanize import Browser br = Browser() br.open('http://somewebpage') html = br.response().readlines() for line in html: print line When print a line in an html file, I'm trying to find a way to only show the contents of each HTML element and not the formatting itself. If it finds '<a href="whatever.com">some text</a>' it will o...

Programmatically generate video or animated GIF in Python?

I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create either a video (AVI, M...

Accessing the class that owns a decorated method from the decorator

Hi, I'm writing a decorator for methods that must inspect the parent methods (the methods of the same name in the parents of the class in which I'm decorating). Example (from the fourth example of PEP 318): def returns(rtype): def check_returns(f): def new_f(*args, **kwds): result = f(*args, **kwds) ...

Inheritance and Overriding __init__ in python

I was reading 'Dive Into Python' and in the chapter on classes it gives this example: class FileInfo(UserDict): "store file metadata" def __init__(self, filename=None): UserDict.__init__(self) self["name"] = filename The author then says that if you want to override the __init__ method, you must explicitly call...

How do you order lists in the same way QuerySets are ordered in Django?

I have a model that has an ordering field under its Meta class. When I perform a query and get back a QuerySet for the model it is in the order specified. However if I have instances of this model that are in a list and execute the sort method on the list the order is different from the one I want. Is there a way to sort a list of in...