我试图用光标搜索access表中一个名为DEV_TYPE的字段中的一些记录。我想将每个记录与我之前在脚本中构建的已知值列表进行比较:
(devcatList)
我想打印出列表中没有出现的值。记录中的某些值也为空。我想将if语句设置为只输出列表中没有出现的值,但也不想为空值打印“None”。我的脚本如下:
if field.name == "DEV_TYPE":
for iRow in arcpy.SearchCursor(fc):
if not iRow.DEV_TYPE is None or iRow.DEV_TYPE not in devcatList:
print str(iRow.OBJECTID) + " - " + str(iRow.DEV_TYPE)
我把if not x is None
'改为if x is not None
。将“or
”改为“and
”(尽管这有违直觉),但我的打印输出要么返回所有值要么不返回值,要么只返回“None
”……基本上我不想要的一切。我肯定我在做傻事。有人能指出我的愚蠢是什么吗?在
谢谢, 迈克
也许是这样的:
由于}。我还冒昧地以更惯用的方式重写了
None
在条件上下文中等同于False
,因此if dev_type is not none
可以更方便地(但不太精确地)声明{print
语句。在我想你想
if iRow.DEV_TYPE is not None and iRow.DEV_TYPE not in devcatList:
相关问题 更多 >
编程相关推荐