Movatterモバイル変換


[0]ホーム

URL:


Change the class of an object

Steve Purcellstephen_purcell at yahoo.com
Fri Apr 13 10:48:22 EDT 2001


Fernando Rodríguez wrote:> Is it possible to change an object's class in runtime? O:-)Yes, but you should be worried if that seems like a good idea. There'susually a better solution. But if you insist:    >>> class Flub:    ...    def flubber(self):    ...       print "Flub"    ...     >>> class Ber:    ...    def flubber(self):    ...       print "Ber"    ...     >>> f = Flub()    >>> f.flubber()    Flub    >>> f.__class__ = Ber    >>> f.flubber()    Ber    >>> -Steve-- Steve Purcell, PythangelistGet testing athttp://pyunit.sourceforge.net/Any opinions expressed herein are my own and not necessarily those of Yahoo


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp