The below snippet of code keeps returning a "NoneType isn't iterable" error. Why doesn't the if statement catch this?
inset = set() for x in node.contacted: print type(x) if x.is_converted() is True: nset.add(x) if x.contacted is None: memotable[node.gen][node.genind] = nset else: nset.union(self.legacy(x, memotable)) memotable[node.gen][node.genind] = nset Full traceback as requested:
Traceback (most recent call last):
File "F:\Dropbox\CS\a4\skeleton\trialtest.py", line 142, in test_legacy_and_frac()
File "F:\Dropbox\CS\a4\skeleton\trialtest.py", line 125, in test_legacy_and_frac cunittest2.assert_equals(set([n10,n12,n21]), t.legacy(n00,mtable))
File "F:\Dropbox\CS\a4\skeleton\trial.py", line 138, in legacy nset.union(self.legacy(x, memotable))
File "F:\Dropbox\CS\a4\skeleton\trial.py", line 138, in legacy nset.union(self.legacy(x, memotable))
TypeError: 'NoneType' object is not iterable
x.contactedbefore this? Showing more code helps.x, so we're left to assume you're either iterating elsewhere, or else your error has nothing to do with the variable you're checking. If you don't provide the code needed to reproduce (or at least understand) your error, it's much harder to fix.