feature wish
Sean 'Shaleh' Perry
shaleh at valinux.com
Fri Mar 2 12:07:53 EST 2001
On 02-Mar-2001 Dan Parisien wrote:
> it seems all the special purpose overloadable methods are to provide type
> emulation through classes
> e.g.
> __nonzero__
> __contains__
> __setitem__
> etc.
>
> it would be cool if there was another method provided that allowed a
> programmer to overload the value returned by an instance as well.
>
> e.g.
>
> class example:
> def __init__(self, name, data):
> self.name = name
> self.data = data
>
> def __value__(self):
> return self.data
>
> eg = example("my name", (1,2,3))
>
>>>>print eg
> (1,2,3)
>
> You could get to the instance behind the value by using a function like
> instance(eg)
>
have you looked into __repr__()?
More information about the Python-list
mailing list