Suggesting for overloading the assign operator

Aahz aahz at pythoncraft.com
Tue Jul 1 20:28:38 CEST 2003


In article <6f03c4a5.0306301931.3f15fbb7 at posting.google.com>,
Rim <rimbalaya at yahoo.com> wrote:
>
>I have been thinking about how to overload the assign operation '='.
>In many cases, I wanted to provide users of my packages a natural
>interface to the extended built-in types I created for them, but the
>assign operator is always forcing them to "type cast" or coerce the
>result when they do a simple assign for the purpose of setting the
>value of a variable. Borrowing an example from this newgroup, the
>second assignment below ereases all Currency knowledge from variable
>'c', when the user only wanted to update the value of c, not its type:
>
>c=Currency(5)
>c=7
>
>I fully understand the workaround of doing c=Curreny(7) instead, but
>users don't want to be bothered with that.

If you have users who don't want to learn Python, give them a special
Python-like language.  I won't say it's trivial, but it's not that hard.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Usenet is not a democracy.  It is a weird cross between an anarchy and a
dictatorship.  




More information about the Python-list mailing list