A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-list/2001-April/093145.html below:

Change the class of an object

Change the class of an object Change the class of an objectSteve Purcell stephen_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's
usually 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, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo


More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4