On Sat, Nov 21, 2009 at 2:10 AM, Dennis Lee Bieber <wlfr...@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
-- http://mail.python.org/mailman/listinfo/python-list