Computed attribute names

Dale Amon amon at vnl.com
Wed Apr 8 14:47:46 EDT 2009


There are a number of things which I have been used
to doing in other OO languages which I have not yet
figured out how to do in Python, the most important
of which is passing method names as args and inserting
them into method calls. Here are two cases I have been
trying to figure out for a current project. 

The first is passing methods to dispatcher methods. In
pseudocode, something like this:

def dispatcher(self,methodname):
    self.obj1.methodname()
    self.obj2.methodname()

and another case is selecting behavior of an object by
setting a type string, with pseudo code like this:

    self.IBM029 = re.compile([^acharset]
    self.IBM026 = re.compile([^anothercharset]
    self.type = "IBM029"
    errs      = self.(self.type).findall(aCardImage)

I have yet to find any way to do either, although it appears
I could do some of it using a long and roundabout call string
using __dict__.

What is the Python dialect for this sort of runtime OO? 



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20090408/632aa724/attachment.sig>


More information about the Python-list mailing list