Re: naming objects from string
- From: "manstey" <manstey@xxxxxxxxxx>
- Date: 20 Sep 2006 21:33:56 -0700
Hi,
But this doesn't work if I do:
a=object()
x='bob'
locals()[x] = a
How can I do this?
James Stroud wrote:
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/
.
- Follow-Ups:
- Re: naming objects from string
- From: Wildemar Wildenburger
- Re: naming objects from string
- From: Damjan
- Re: naming objects from string
- References:
- naming objects from string
- From: manstey
- Re: naming objects from string
- From: James Stroud
- naming objects from string
- Prev by Date: i just made a website(ztooo.com) using zope & jsonserver
- Next by Date: Re: Trying to run an external program
- Previous by thread: Re: naming objects from string
- Next by thread: Re: naming objects from string
- Index(es):
Relevant Pages
|