Replace Whole Object Through Object Method

John Roth JohnRoth1 at jhrothjr.com
Sat Jul 1 11:23:23 EDT 2006


digitalorganics at gmail.com wrote:
> How can an object replace itself using its own method? See the
> following code

[code deleted]

At the risk of creating totally incomprehensible and
unmaintainable code, you need two things:

First, you can change the class of any new style
object by assigning to the __class__ attribute.

Second, you can create a new style class
on the fly with the three operand type(a, b, c) method.
See the builtin methods in the doc.

It's quite straightforward if you know what you're
doing. What's hard is to create a conceptual model
that won't be an instant winner in an obfuscated code
contest.

John Roth

>




More information about the Python-list mailing list