indirect references
Darrell Gallion
darrell at dorb.com
Tue Jun 6 00:37:03 EDT 2000
From: <shaleh at debian.org>
> How do I do this in python:
>
> foo = 'string'
> bar = foo
>
> somehow assign to bar and change the value of foo.
>
Dictionary keys can act like pointers.
>>> dic={id(str1):'str1'}
>>> b=id(str1)
>>> c=id(str1)
>>> dic[c]='newStr'
>>> dic[b]
'newStr'
The objects address makes a pretty good key.
This is also handy to avoid circular references.
Not as pretty as pointers, but I think less confusing.
--Darrell Gallion
More information about the Python-list
mailing list