Re: substitution __str__ method of an instance

2008-10-24 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > However, you can dispatch back to the instance if you really must: > > > class MyObj(object): > def __init__(self): > self.__str__ = lambda self: "I'm an object!" > def __str__(self): > return self.__str__(self) > > > But hon

Re: substitution __str__ method of an instance

2008-10-23 Thread Steven D'Aprano
On Thu, 23 Oct 2008 10:55:56 +0200, Christian Heimes wrote: > netimen wrote: >> How can I substitute __str__ method of an instance? > > It's not possible. For performance and other reasons most __*__ methods > are looked up on the type only. > > Christian However, you can dispatch back to the i

Re: substitution __str__ method of an instance

2008-10-23 Thread Bruno Desthuilliers
Diez B. Roggisch a écrit : Christian Heimes wrote: netimen wrote: How can I substitute __str__ method of an instance? It's not possible. For performance and other reasons most __*__ methods are looked up on the type only. Is that documented somewhere? I *know* it is that way, yet I'd like t

Re: substitution __str__ method of an instance

2008-10-23 Thread Bruno Desthuilliers
netimen a écrit : I couldn't substitute __str__ method of an instance. Though I managed to substitute ordinary method of an instance: from types import MethodType class Foo(object): pass class Printer(object): def __call__(self, obj_self): return 'printed' f = Foo() f.printe

Re: substitution __str__ method of an instance

2008-10-23 Thread Diez B. Roggisch
Christian Heimes wrote: > netimen wrote: >> How can I substitute __str__ method of an instance? > > It's not possible. For performance and other reasons most __*__ methods > are looked up on the type only. Is that documented somewhere? I *know* it is that way, yet I'd like to have place to read

Re: substitution __str__ method of an instance

2008-10-23 Thread Diez B. Roggisch
netimen wrote: > I couldn't substitute __str__ method of an instance. Though I managed > to substitute ordinary method of an instance: > > from types import MethodType > > class Foo(object): > pass > > class Printer(object): > > def __call__(self, obj_self): > return 'printed'

Re: substitution __str__ method of an instance

2008-10-23 Thread Christian Heimes
netimen wrote: How can I substitute __str__ method of an instance? It's not possible. For performance and other reasons most __*__ methods are looked up on the type only. Christian -- http://mail.python.org/mailman/listinfo/python-list