Label-Value (was: Re: Inheriting the @ sign from Ruby)
Rainer Deyke
root at rainerdeyke.com
Fri Dec 15 12:16:33 EST 2000
"Rainer Deyke" <root at rainerdeyke.com> wrote in message
news:rOr_5.31120$x6.15241856 at news2.rdc2.tx.home.com...
> Yes, in-place modification should be supported. I had something like this
> in mind:
>
> class UserInt:
> def __init__(self, value):
> self.data = value
> def __add__(self, other):
> if isinstance(other, UserInt):
> return self.__class__(self.data + other.data)
> else:
> return self.__class__(self.data + other)
> __radd__ = __add__
> def __iadd__(self, other):
> if isinstance(other, UserInt):
> self.data += other.data
> else:
> self.data += other
> # Repeat for all other operations
>
> UserInt as written is more properly UserNumber, since it supports longs
ints
> and floats.
Of course __iadd__ actually belongs in MutableInt instead of UserInt, but
that didn't occur to me until after I'd written it.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list