manstey wrote:
[...]
> bob_apple=()
> bob_orange=()
> ..
> pete_red=()
>
> I then populate the 9 tuples with data [...]
You cannot "populate" a tuple. If you want to insert the values
individually, you have to use a list. If you insert them all together,
like this: bob_apple = (1, 2, ..., 9),
"James Stroud" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Depends on your namespace, but for the local namespace, you can use this:
>
> py> a = object()
> py> a
>
> py> locals()['bob'] = a
> py> bob
>
If you put this code within a function, it probably will not work.
locals
manstey wrote:
> so they might provide a list of names, like 'bob','john','pete', with 3
> structures per name, such as 'apple','orange','red' and I need 9 tuples
> in my code to store their data:
>
> bob_apple=()
> bob_orange=()
> ..
> pete_red=()
I really think you should be using dictionaries
manstey wrote:
> so they might provide a list of names, like 'bob','john','pete', with 3
> structures per name, such as 'apple','orange','red' and I need 9 tuples
> in my code to store their data:
>
> bob_apple=()
> bob_orange=()
> ..
> pete_red=()
>
> I then populate the 9 tuples with data they
At Thursday 21/9/2006 00:59, manstey 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)
and then a function
name(b) = a
which would mean:
hello=(1234)
is this possible?
You may use another object as a namespace:
class
"manstey" <[EMAIL PROTECTED]> 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)
>
>i
"manstey" <[EMAIL PROTECTED]> writes:
> If I have a string, how can I give that string name to a python
> object, such as a tuple.
The thing I'd like to know before answering this is: how will you be
using that name to refer to the object later?
--
\ "If you ever catch on fire, try to avoi
manstey wrote:
> Hi,
>
> thanks for the suggestions. this is my problem:
>
> I have a metadata file that another user defines, and I don't know
> their structure in advance. They might have 300+ structures. the
> metadata defines the name and the tuple-like structure when read by
> python.
>
> m
Hi,
thanks for the suggestions. this is my problem:
I have a metadata file that another user defines, and I don't know
their structure in advance. They might have 300+ structures. the
metadata defines the name and the tuple-like structure when read by
python.
my program reads in the metadata fil
Hi,
thanks for the suggestions. this is my problem:
I have a metadata file that another user defines, and I don't know
their structure in advance. They might have 300+ structures. the
metadata defines the name and the tuple-like structure when read by
python.
my program reads in the metadata fil
Damjan wrote:
> try
> sys.modules[__name__].__dict__[x] = a
@manstay: You see! Ugly, unreadable trickery!
Hands off this stuff, bad mojo!
You've been told three very different approaches now, which is a pretty
good indicator that there is no obvious way to do it. Which means
another angle to yo
manstey wrote:
> Hi,
>
> But this doesn't work if I do:
>
> a=object()
> x='bob'
> locals()[x] = a
>
> How can I do this?
You can. I just copy/pasted your code and it works fine here. (You are
aware that there is whitespace before locals() that you have to remove
before you feed it to the sn
manstey wrote:
> Hi,
>
> But this doesn't work if I do:
>
> a=object()
> x='bob'
> locals()[x] = a
>
> How can I do this?
try
sys.modules[__name__].__dict__[x] = a
But what's the point?
--
damjan
--
http://mail.python.org/mailman/listinfo/python-list
manstey 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)
>
> and then a function
> name(b) = a
>
> which would mean:
> hello=(1234)
>
> is this possible?
>
Direct answer:
Look up the setattr() functions (D
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 t
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 l
16 matches
Mail list logo