One caveat, as I recently discovered, to dynamically adding methods is
that it doesn't work for __foo__ methods. For example, you can't make
an object into an iterator by dynamically assigning bound methods to
obj.__iter__ and obj.next. Same thing with __getitem__, __setitem__,
etc; adding them directly to the instance doesn't get you a
subscriptable object. This is because the interpreter looks at the
methods defined by the class, rather than the instance's attributes.

Just a word of caution.

Collin Winter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to