naming objects from string

Tim Roberts timr at
Thu Sep 21 08:39:19 CEST 2006

"manstey" <manstey at> wrote:
>If I have a string, how can I give that string name to a python object,
>such as a tuple.
>a = 'hello'

That's not a tuple.  That's an integer.  (1234,) is a tuple.

>and then a function
>name(b) = a
>which would mean:
>is this possible?

Yes, but it's almost never the right way to solve your problem.  Use an
explicit dictionary instead.

    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
- Tim Roberts, timr at
  Providenza & Boekelheide, Inc.

More information about the Python-list mailing list