Re: naming objects from string



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/
.



Relevant Pages

  • Re: converting to string
    ... I believe that marshal is the most efficient method to convert a python object to a string. ... Joshua Moore-Oliva ...
    (comp.lang.python)
  • Re: python socket usage
    ... Python object of any type and complexity into a byte string which can be ... sent across a socket. ... I need to talk with a Java ...
    (comp.lang.python)
  • Re: converting to string
    ... > how do i go about converting a Python object or tuple to a string. ... > import cPickle as pickle ...
    (comp.lang.python)
  • Re: python socket usage
    ... It seems with socket module it is only possible to ... what a string is after all) into a tuple is an easy operation, ... Python object of any type and complexity into a byte string which can be ...
    (comp.lang.python)
  • Re: converting to string
    ... >> how do i go about converting a Python object or tuple to a string. ... > you can write a C extension that allocates a big string and copies every ...
    (comp.lang.python)