【发布时间】:2018-05-18 14:17:00
【问题描述】:
所以基本上我正在编写一些代码来交叉检查我的数据是否一致。 我已经编写了下面的代码,但它一直显示 TypeError:'NoneType' 类型的参数不可迭代,我尝试更改代码很多次,但仍然出现相同的错误。非常感谢。
def checkdata(sex,school):
if (sex == 'F') and ('boys school' in school) :
return 'inconsistent'
if (sex == 'M') and ('girls school' in school):
return 'inconsistent'
return
def Dif() :
with arcpy.da.UpdateCursor(DATA_SET,
[sex, school]) as Cursor :
for Cols in Cursor :
Data = checkdata(Cols[0], Cols[1])
if Data is not None:
print (Data, " ",Cols)
【问题讨论】:
-
我怀疑错误消息在
for语句中(您未能包含完整的错误消息),这意味着Cursor是None,而不是您所期望的。使用一个或两个print语句来跟踪您正在使用的值。如果仍有问题,请发帖Minimal, complete, verifiable example。在您发布 MCVE 代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您描述的问题。 -
在哪里发生错误?顺便说一句,我认为在
checkdata()末尾显式返回None会更好... -
事实上,完整的错误信息表明错误出在这两个代码上: if (sex == 'F') and ('boys school' in school) : return 'inconsistent' if ( sex == 'M') and ('girls school' in school): return 'inconsistent' >>>