En Mon, 18 Aug 2008 11:02:20 -0300, gundlach <[EMAIL PROTECTED]> escribió:
> In C or C++, what you want to do is impossible. However, in Python,
> there's a way to specify the name of a local variable at runtime:
>
> locals()['cat'] = []
>
> locals() is a function call that returns a dictionary m
Hi Bruce,
I think I get what you're asking for -- you want to actually end up
with a local variable 'cat' which points to an empty list, so that you
can then do
cat.append('foot')
or whatever.
The problem with the last line of this code (based on your attempt):
foo=[]
foo.append('cat')
foo[0]
bruce a écrit :
hi guys/gals...
got a basic question that i can't get my hands around.
i'm trying to programatically create/use a list/tuple (or whatever the right
phrase in pyton is!!)
basically, something like:
foo = []
foo.append('cat')
foo.append('dog')
foo[1] = [] (and in this case,
bruce wrote:
so, this still doesn't get me an array called 'cat', or 'dog'
sure does, in the stuff dictionary:
>>> stuff = {}
>>> foo = []
>>> foo.append('cat')
>>> foo.append('dog')
>>> stuff[foo[1]] = []
>>> stuff
{'dog': []}
(note that Python indexing starts with zero, so foo[1] refers to
8 2:27 PM
To: python-list@python.org
Subject: Re: list/tuple/dict question
bruce wrote:
> a dict doesn't seem to work, as it is essentially a series of key/values,
> which isn't exactly what i want...
so what do you think a variable namespace is?
as usual, Python works best i
bruce wrote:
a dict doesn't seem to work, as it is essentially a series of key/values,
which isn't exactly what i want...
so what do you think a variable namespace is?
as usual, Python works best if you use it to write Python program, and
in Python, the right way to store a collection of nam
hi guys/gals...
got a basic question that i can't get my hands around.
i'm trying to programatically create/use a list/tuple (or whatever the right
phrase in pyton is!!)
basically, something like:
foo = []
foo.append('cat')
foo.append('dog')
foo[1] = [] (and in this case, i really want to h