Note that there are some explanatory texts on larger screens.

plurals
  1. POPython list recursion type error
    primarykey
    data
    text
    <p>Solved: It seems that the problem only occurs with PythonWin. I ran everything through the IDLE's python shell and it worked just fine. Must be a bug with PythonWin and not the code itself. </p> <p>I can't seem to figure out why the following code is giving me a <code>TypeError: 'type' object is not iterable</code></p> <p>pastebin: <a href="http://pastebin.com/VFZYY4v0" rel="nofollow">http://pastebin.com/VFZYY4v0</a></p> <pre><code>def genList(self): #recursively generates a sorted list of child node values numList = [] if self.leftChild != 'none': numList.extend(self.leftChild.genList()) #error numList.extend(list((self.Value,))) if self.rightChild != 'none': numList.extend(self.rightChild.genList()) #error return numList </code></pre> <p>code that adds child nodes (works correctly)</p> <pre><code>def addChild(self, child): #add a child node. working if child.Value &lt; self.Value: if self.leftChild == 'none': self.leftChild = child child.parent = self else: self.leftChild.addChild(child) elif child.Value &gt; self.Value: if self.rightChild == 'none': self.rightChild = child child.parent = self else: self.rightChild.addChild(child) </code></pre> <p>Any help would be appreciated.</p> <p>Full interpreter session: &gt;&gt;&gt; import BinTreeNode as BTN<br /> &gt;&gt;&gt; node1 = BTN.BinaryTreeNode(5)<br /> &gt;&gt;&gt; node2 = BTN.BinaryTreeNode(2)<br /> &gt;&gt;&gt; node3 = BTN.BinaryTreeNode(12)<br /> &gt;&gt;&gt; node3 = BTN.BinaryTreeNode(16)<br /> &gt;&gt;&gt; node4 = BTN.BinaryTreeNode(4)<br /> &gt;&gt;&gt; node5 = BTN.BinaryTreeNode(13)<br /> &gt;&gt;&gt; node1.addChild(node2)<br /> &gt;&gt;&gt; node1.addChild(node3)<br /> &gt;&gt;&gt; node1.addChild(node4)<br /> &gt;&gt;&gt; node1.addChild(node5)<br /> &gt;&gt;&gt; node4.genList()<br /> &lt;class 'list'&gt;<br /> &gt;&gt;&gt; node1.genList()<br /> Traceback (most recent call last):<br /> File "&lt;interactive input&gt;", line 1, in &lt;module&gt;<br /> File "C:...\python\BinTreeNode.py", line 47, in genList<br /> numList.extend(self.leftChild.genList()) #error<br /> File "C:...\python\BinTreeNode.py", line 52, in genList<br /> TypeError: 'type' object is not iterable<br /></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload