下面的代碼片段會一直返回「NoneType is not iterable」錯誤。爲什麼if語句不能解決這個問題?根據要求Python'if x is None'not catch NoneType None
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
完全回溯:
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
請張貼全回溯。它有助於理解這個問題。 – pradyunsg
你在迭代'x。在此之前聯繫過嗎?顯示更多代碼有助於。 –
請將您的程序減少到仍然顯示錯誤的最短完整程序。然後將*程序複製粘貼到您的問題中。請參閱http://SSCCE.org瞭解更多信息。 –