unsupported operand type(s) for %: 'NoneType' and 'tuple'

Carsten Haese carsten.haese at gmail.com
Mon Dec 7 10:29:20 EST 2009


Victor Subervi wrote:
> I'll do my best to remember to do that from
> now on to:
> 
>>>> allTrees = [{'prodCat1': {}, 'prodCat2': {}}, {'presCat1': {},
> 'presCat2': {}}]
>>>> level = 0
>>>> tree = []
>>>> for aTree in allTrees:
> ...   for name in sorted(aTree.keys()):
> ...     tree.append("%s%s" % ("\t" * level, name))
> ...     print aTree([name], level + 1)
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 4, in ?
> TypeError: 'dict' object is not callable
>>>>
> 
> So It would seem I need to either figure a way to coerce the dicts into
> being tuples a la:
> http://code.activestate.com/recipes/361668/
> (which looks like a lot of work) or I need to supply tuples instead of
> dicts.

No. You need to test the actual code you want to test. The code you
typed manually has some very significant differences from the code you
first posted. For example, one uses <<printTree(aTree[name], level +
1)>>, and the other uses <<print aTree([name], level + 1)>>. The
conclusions you are drawing from this test are meaningless guesses that
have nothing to do with solving your actual problem.

> The dicts come from here:
> 
> cursor.execute('select category from categories%s order by Category;' %
> (store[0].upper() + store[1:]))
> theTree = expand(cursor.fetchall())
> 
> which is the magical code supplied by the lister that does all the heavy
> lifting but that I don't understand :-}
> Suggestions?

Start by understanding the code you're using.

--
Carsten Haese
http://informixdb.sourceforge.net




More information about the Python-list mailing list