Too Many Values To Unpack

Victor Subervi victorsubervi at gmail.com
Sat Nov 21 09:27:21 EST 2009


On Sat, Nov 21, 2009 at 2:10 AM, Dennis Lee Bieber <wlfraed at ix.netcom.com>wrote:

>        And my follow-up to that original thread stated that it /was/
> pseudo-code, not something tested.  My goal was to illustrate the
> general concepts of processing a recursive/nested data set stored in a
> flat/relational table.
>

Of course and appreciated.

>
>        "expand()" was responsible for taking each "key" from a select query
> and creating an empty dictionary with that "key" as, well, key. Then the
> recursive operation would perform a select query used to populate the
> empty dictionary, ad infinitum.
>

Here is the output with just one test category:
{'cat1': {}}

Here is the code to which that output is fed:

def getChildren(levelDict, level = 0):
  MAXLEVEL = 7
  if level > MAXLEVEL:
    return  #possibly the data has a cycle/loop
  for (nm, dt) in levelDict:
    cursor.execute('''select c.name from categories as c
      inner join relationship as r
      on c.ID = r.Child
      inner join categories as p
      on r.Parent = p.ID
      where p.category = %s
      order by c.name''', (nm,))
    levelDict[nm] = expand(cursor.fetchall())
    # recursive call to do next level
    getChildren(levelDict[nm], level + 1)
  # no data return as we are mutating dictionaries in place

When this script is called from another script, the python interpreter
throws the following error:

Traceback (most recent call last):
  File "createCats.py", line 8, in ?
    from catTree import catTree
  File "/var/www/html/angrynates.com/cart/catTree.py", line 85, in ?
    catTree()
  File "/var/www/html/angrynates.com/cart/catTree.py", line 76, in catTree
    getChildren(theTree)
  File "/var/www/html/angrynates.com/cart/catTree.py", line 25, in
getChildren
    for (nm, dt) in levelDict:
ValueError: too many values to unpack

Please advise.
TIA,
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091121/be8a9cfa/attachment-0001.html>


More information about the Python-list mailing list