<div class="gmail_quote">On Sat, Nov 21, 2009 at 2:10 AM, Dennis Lee Bieber <span dir="ltr"><<a href="mailto:wlfraed@ix.netcom.com">wlfraed@ix.netcom.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
       And my follow-up to that original thread stated that it /was/<br>
pseudo-code, not something tested.  My goal was to illustrate the<br>
general concepts of processing a recursive/nested data set stored in a<br>
flat/relational table.<br></blockquote><div><br>Of course and appreciated. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
        "expand()" was responsible for taking each "key" from a select query<br>
and creating an empty dictionary with that "key" as, well, key. Then the<br>
recursive operation would perform a select query used to populate the<br>
empty dictionary, ad infinitum.<br></blockquote><div><br>Here is the output with just one test category:<br>{'cat1': {}}<br><br></div></div>Here is the code to which that output is fed:<br><br>def getChildren(levelDict, level = 0):<br>
  MAXLEVEL = 7<br>  if level > MAXLEVEL:<br>    return  #possibly the data has a cycle/loop<br>  for (nm, dt) in levelDict:<br>    cursor.execute('''select <a href="http://c.name">c.name</a> from categories as c<br>
      inner join relationship as r<br>      on c.ID = r.Child<br>      inner join categories as p<br>      on r.Parent = p.ID<br>      where p.category = %s<br>      order by <a href="http://c.name">c.name</a>''', (nm,))<br>
    levelDict[nm] = expand(cursor.fetchall())<br>    # recursive call to do next level<br>    getChildren(levelDict[nm], level + 1)<br>  # no data return as we are mutating dictionaries in place<br><br>When this script is called from another script, the python interpreter throws the following error:<br>
<br>Traceback (most recent call last):<br>  File "createCats.py", line 8, in ?<br>    from catTree import catTree<br>  File "/var/www/html/<a href="http://angrynates.com/cart/catTree.py">angrynates.com/cart/catTree.py</a>", line 85, in ?<br>
    catTree()<br>  File "/var/www/html/<a href="http://angrynates.com/cart/catTree.py">angrynates.com/cart/catTree.py</a>", line 76, in catTree<br>    getChildren(theTree)<br>  File "/var/www/html/<a href="http://angrynates.com/cart/catTree.py">angrynates.com/cart/catTree.py</a>", line 25, in getChildren<br>
    for (nm, dt) in levelDict:<br>ValueError: too many values to unpack<br><br>Please advise.<br>TIA,<br>V<br>