Nested Dicts
MRAB
python at mrabarnett.plus.com
Sat Dec 5 11:25:03 EST 2009
Victor Subervi wrote:
> Hi;
> I have the following error:
>
> /var/www/html/angrynates.com/cart/catTree.py
> <http://angrynates.com/cart/catTree.py> in
> getChildren(levelDict={'cat3': {}}, level=0)
> 23 if level > MAXLEVEL:
> 24 return #possibly the data has a cycle/loop
> 25 for (nm, dt) in levelDict: ### ERROR HERE
> 26 cursor.execute('''select c.name <http://c.name> from
> categories as c
> 27 inner join relationship as r
> nm undefined, dt undefined, levelDict = {'cat3': {}}
>
> ValueError: too many values to unpack
> args = ('too many values to unpack',)
>
> However...
>
> >>> d = {'cat': {'one':'two'}}
> >>> for a, b in d:
> ...
> File "<stdin>", line 2
>
> ^
> IndentationError: expected an indented block
> >>> d = {'cat': {}}
> >>> for a, b in d:
> ...
> File "<stdin>", line 2
>
> ^
> IndentationError: expected an indented block
> >>>
>
> So apparently, if either the nested dict is populated or not doesn't
> seem to throw any errors in the interpreter. What, then, is the nature
> of this error?
>
When you iterate through a dict, it yields the keys. It's all in the
documentation.
More information about the Python-list
mailing list