floatref

Roald de Vries downaold at gmail.com
Wed Jul 14 03:56:08 EDT 2010


On Jul 14, 2010, at 1:26 AM, Gary Herron wrote:
> On 07/13/2010 03:02 PM, Roald de Vries wrote:
>> Hi Gary,
>>
>> On Jul 13, 2010, at 8:54 PM, Gary Herron wrote:
>>> On 07/13/2010 10:26 AM, Roald de Vries wrote:
>>>> Hi all,
>>>>
>>>> I have two objects that should both be able to alter a shared  
>>>> float.
>>>> So i need something like a mutable float object, or a float  
>>>> reference
>>>> object. Does anybody know if something like that exists? I know  
>>>> it's
>>>> not hard to build, but I have a feeling that there should be a
>>>> standard solution to it.
>>>>
>>>> Roald
>>>
>>> Huh? I must be missing something here. Isn't this what you use a
>>> variable for:
>>
>> Maybe I didn't explain well:
>>
>> >>> shared_var = 1.0
>> >>> x.var = shared_var
>> >>> y.var = shared_var
>> >>> x.var = 2.0
>> >>> y.var
>> 1.0
>>
>> I wanted y.var and x.var to point to the same value, so that always
>> x.var == y.var. So that the last line becomes:
>>
>> >>> y.var
>> 2.0
>>
>> Cheers, Roald
>
> Please keep responses and further discussions on
>  list.python-list at python.org
> instead of using private emails.

Sorry.

> Python does not have pointers, so if I take your wording"y.var and  
> x.var to point to the same value"  literally, then the answer is NO   
> Python does not do that.

Maybe I should have put it between quotes, but I used the words  
'mutable float' and 'float reference' in the original post, and this  
was only an attempt to clarify better.

> However, Python does have references all over the place, so you can  
> achieve something similar in many ways.

I know, I just wondered if there is a *standard* solution.

Cheers, Roald



More information about the Python-list mailing list