unsupported operand type(s) for %: 'NoneType' and 'tuple'
Jean-Michel Pichavant
jeanmichel at sequans.com
Mon Dec 7 07:14:12 EST 2009
Victor Subervi wrote:
>
> global printTree = <function printTree>, allTrees = [{'prodCat1': {},
> 'prodCat2': {}}, {'presCat1': {}, 'presCat2': {}}]
> /var/www/html/angrynates.com/cart/catTree.py
> <http://angrynates.com/cart/catTree.py> in
> printTree(allTrees=[{'prodCat1': {}, 'prodCat2': {}}, {'presCat1': {},
> 'presCat2': {}}], level=0)
> 12 for name in sorted(aTree.keys()):
> 13 print '\t' * level, name
> 14 tree.append("%s%s") % ("\t" * level, name)
> 15 printTree(aTree[name], level + 1)
> 16
> tree = ['%s%s'], tree.append = <built-in method append of list
> object>, level = 0, name = 'prodCat1'
>
> TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'
> args = ("unsupported operand type(s) for %: 'NoneType' and
> 'tuple'",)
>
> But according to the same error, level = 0 [the NoneType, I presume]
> and name = 'prodCat1', which is most certainly not a tuple! Why the error?
> TIA,
> Victor
Come on Victor,
Given the error, you can easily see that
tree.append("%s%s") % ("\t" * level, name)
is involved in the error you get.
The correct thing may be
tree.append("%s%s" % ("\t" * level, name))
It should be easy for you to spot.
FYI, tree.append('%s%s') returns None, then ("\t" * level, name) is the
tuple applied to None through the % operator. That is why you get the
above error.
Cheers,
JM
More information about the Python-list
mailing list