Re: [Tutor] Overloading the assignment operator in a class

2006-09-21 Thread Alan Gauld
>> mydie = Die(mydie.n,5) >> >> And I believe you can do that by implementing the __coerce__ >> method. - but I've never tried it... > > If you can do that with __coerce__, I'm not clever enough to figure > out > how. IIRC, Python only calls __coerce__ if you're using arithmetic > operators on dif

Re: [Tutor] Overloading the assignment operator in a class

2006-09-20 Thread Kent Johnson
Carroll, Barry wrote: > How do I overload the '=' operator to give the desired behavior? This classic essay talks about the meaning of assignment in Python: http://www.effbot.org/zone/python-objects.htm Also I don't think there is any need to overload __lt__, etc.; just __cmp__ is enough, it wil

Re: [Tutor] Overloading the assignment operator in a class

2006-09-20 Thread wesley chun
On 9/20/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > This all seems to work okay. > > > > I want the assignment operator ('=') > > There is no assignment operator in Python, assignment is a > binding of an object to a name. as others have mentioned, the assignment operator is used to assign an o

Re: [Tutor] Overloading the assignment operator in a class

2006-09-20 Thread Jordan Greenberg
Alan Gauld wrote: >> This all seems to work okay. >> >> I want the assignment operator ('=') > > There is no assignment operator in Python, assignment is a > binding of an object to a name. > >> to call the >> set method transparently on Die instances, >> as in this fictitious example: > >

Re: [Tutor] Overloading the assignment operator in a class

2006-09-20 Thread Jordan Greenberg
Carroll, Barry wrote: > Greetings: > > I have a class that implements a die (singular or dice). Here is the class > definition: > How do I overload the '=' operator to give the desired behavior? > > Regards, > > Barry AFAIK, you can't. Unlike, say, Java or C++, the assignment operator is no

Re: [Tutor] Overloading the assignment operator in a class

2006-09-20 Thread Alan Gauld
> This all seems to work okay. > > I want the assignment operator ('=') There is no assignment operator in Python, assignment is a binding of an object to a name. > to call the > set method transparently on Die instances, > as in this fictitious example: @BCARROLL[Python]|6> mydie = 5 @BCA

[Tutor] Overloading the assignment operator in a class

2006-09-20 Thread Carroll, Barry
Greetings: I have a class that implements a die (singular or dice). Here is the class definition: >>> class Die(object): """Implements a gaming die. Attributes: n: the number of sides Must correspond to the number of sides on a physical die. val