Add a method to an existing class

Alex Martelli aleaxit at yahoo.com
Wed May 16 17:41:27 EDT 2001


"Bruce Edge" <bedge at troikanetworks.com> wrote in message
news:20010516.100608.1372261796.19522 at mead.troikanetworks.com...
    ...
> >>> class xx:
    ...
> >>> xx.__dict__['__repr__']=str
    ...
> It works, but I'm wondering if this is the right way.

xx.__repr__ = str

may be simpler.  but call that function something else
than str -- the latter is too useful a builtin:-).


Alex






More information about the Python-list mailing list