Modifying the value of a float-like object
Ben Finney
ben+python at benfinney.id.au
Wed Apr 15 00:17:40 EDT 2009
Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> writes:
> On Tue, 14 Apr 2009 06:03:58 -0700, Eric.Le.Bigot wrote:
> > 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.
>
> Why is that the goal? If you want to change the value of x, just
> change the value of x.
As you're aware (but Eric may not be), Python doesn't have “change the
value of x”. The closest would be to re-bind the name ‘x’ to a different
value, which would not be what Eric is asking for.
If I understand correctly, Eric wants something with the following
behaviour:
>>> foo = [floatref(3.14), floatref(1.41)]
>>> bar = foo[0]
>>> baz = foo[1]
>>> foo
[3.14, 1.41]
>>> (bar, baz)
(3.14, 1.41)
>>> foo[1].changevalue(1.62)
>>> foo
[3.14, 1.62]
>>> (bar, baz)
(3.14, 1.62)
and is asking how to get such a ‘floatref’.
--
\ “If you go parachuting, and your parachute doesn't open, and |
`\ you friends are all watching you fall, I think a funny gag |
_o__) would be to pretend you were swimming.” —Jack Handey |
Ben Finney
More information about the Python-list
mailing list