naming objects from string

James Stroud jstroud at mbi.ucla.edu
Thu Sep 21 00:26:07 EDT 2006


manstey wrote:
> Hi,
> 
> If I have a string, how can I give that string name to a python object,
> such as a tuple.
> 
> e.g.
> 
> a = 'hello'
> b=(1234)
> 
> and then a function
> name(b) = a
> 
> which would mean:
> hello=(1234)
> 
> is this possible?
> 

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>

A similar approach can be used for the global namespace.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list