Modifying the value of a float-like object

MRAB google at mrabarnett.plus.com
Tue Apr 14 12:19:25 EDT 2009


Christian Heimes wrote:
> Eric.Le.Bigot at spectro.jussieu.fr wrote:
>> Hello,
>>
>> Is there a way to easily build an object that behaves exactly like a
>> float, but whose value can be changed?  The goal is to maintain a list
>> [x, y,…] of these float-like objects, and to modify their value on the
>> fly (with something like x.value = 3.14) so that any expression like "x
>> +y" uses the new value.
> 
> 
> Your approach doesn't follow the Python philosophy thus it's most likely
> to fail. It is possible to implement a mutable float like object --
> Python doesn't stop you from shooting yourself in the knee -- but please
> don't harm yourself.
> 
[snip]
The saying is actually "shooting yourself in the foot", but then that's
like what happens when you don't follow the Python philosophy! :-)



More information about the Python-list mailing list