naming objects from string
Terry Reedy
tjreedy at udel.edu
Thu Sep 21 07:13:52 EDT 2006
"James Stroud" <jstroud at mbi.ucla.edu> wrote in message
news:zvoQg.3828$e66.1118 at newssvr13.news.prodigy.com...
> Depends on your namespace, but for the local namespace, you can use this:
>
> py> a = object()
> py> a
> <object object at 0x40077478>
> py> locals()['bob'] = a
> py> bob
> <object object at 0x40077478>
If you put this code within a function, it probably will not work.
locals() is usually a *copy* of the local namespace and writes do not write
back to the namespace itself.
tjr
More information about the Python-list
mailing list