[Tutor] Stopping evalualtion of inner Lists/ tuples
Remco Gerlich
scarblac@pino.selwerd.nl
Tue, 23 Jan 2001 12:03:21 +0100
On Tue, Jan 23, 2001 at 05:42:14AM -0500, Sharriff Aina wrote:
> Hi Guys!
>
> Considering the following:
>
> tab1 = {"feld1": "varchar", "feld2": "varchar"}
> tab2 = {"feld3": "varchar", "feld4": "varchar"}
> virtuallist = [tab1, tab2]
Now, virtuallist stores *references* to tab1 and tab2. It doesn't know their
names.
> >>> vlist
> [{'feld2': 'varchar', 'feld1': 'varchar'}, {'feld3': 'varchar', 'feld4':
> 'varchar'}]
> >>> for x in vlist:
> print x
>
> {'feld2': 'varchar', 'feld1': 'varchar'}
> {'feld3': 'varchar', 'feld4': 'varchar'}
>
> >>> for x in vlist:
> print `x`
>
> {'feld2': 'varchar', 'feld1': 'varchar'}
> {'feld3': 'varchar', 'feld4': 'varchar'}
>
> How can I stop the evaluation of the innner List or tuple?
They were already evaluated at the "tab1 = " line. vlist keeps references to
these lists, but doesn't know that there happen to be names for these lists.
I would like to
> have
>
> for tables in virtuallist:
> print tables
>
> >>> tab1
> tab2
You probably want to make a dictionary instead of a list.
Try:
virtuallist = {'tab1': tab1, 'tab2': tab2 }
for name, table in virtuallist.items():
print name, table
Hope this helps.
--
Remco Gerlich