On Jan 24, 12:35 pm, William Pursell <[EMAIL PROTECTED]> wrote:
> I'm not sure that describes the method well.  Basically, you can
> instantiate an object A of class Foo, and later change A to be an
> object of class Bar.   Does Python support this type of flexibility?
> As I stated above, I've been away from Python for awhile now, and am a
> bit rusty,  but it seems that slots or "new style" objects might
> provide this type of behavior.  The ability to have an object change
> class is certainly  (to me) a novel idea.  Can I do it in Python?

Short answer: yes, easily.

Long answer: observe.

>>> class Foo(object):
...   def foo(self): print "Foo.foo"
...
>>> class Bar(object):
...   def foo(self): print "Bar.foo"
...
>>> a = Foo()
>>> a.__class__ = Bar
>>> a.foo()
Bar.foo
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to