naming objects from string
Tim Roberts
timr at probo.com
Thu Sep 21 02:39:19 EDT 2006
"manstey" <manstey at csu.edu.au> wrote:
>
>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)
That's not a tuple. That's an integer. (1234,) is a tuple.
>and then a function
>name(b) = a
>
>which would mean:
>hello=(1234)
>
>is this possible?
Yes, but it's almost never the right way to solve your problem. Use an
explicit dictionary instead.
C:\Tmp>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a='hello'
>>> locals()[a] = 1234
>>> hello
1234
>>>
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list