Label-Value

Carel Fellinger cfelling at iae.nl
Tue Dec 12 17:50:17 EST 2000


Daniel Wood <daniel at cs.washington.edu> wrote:

> Hmmm, I'm open to the suggestion that I need to rethink my plan at a
> larger scale, but isn't a mutable int likely to sometimes be useful?
> (Just like a mutable list is sometimes useful.)  And if so, is [ 2 ]
> the currently favored idiom?  (And if so, isn't there something
> better?)

What about a class? The only thing that is impossible is to set a new
value to its instances with the "instance = value" syntax. But then
neither does "a=1; a=2" assign a new value to "a", it simply makes "a
refer to a different object as Frederiq has explained recently on the
list.  So the proper way to bind new values to an instance is to
generate a new instance like "a = MutableInt(3)", but then "a.set(3)"
might be acceptable in many cases. The fun of using a class is that
given it has the needed special methods defined you can easily use
this mutable-int-instance in expressions like in "a * 3".

-- 
groetjes, carel



More information about the Python-list mailing list