Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ArcGIS Python标签表达式错误_Python_Arcgis - Fatal编程技术网

ArcGIS Python标签表达式错误

ArcGIS Python标签表达式错误,python,arcgis,Python,Arcgis,我最近开始学习Python,并开始使用它在ArcMap中创建标签表达式。我今天遇到了一个错误,我无法理解(看起来应该很简单)。当我尝试创建以下表达式时: def FindLabel ( [FacilityName] ): S = [FacilityName] S = S.upper() return S 我返回一个错误,如下所示: Error 0 on line 0. Error running expression: FindLabel(ESRIExpressionArg0)

我最近开始学习Python,并开始使用它在ArcMap中创建标签表达式。我今天遇到了一个错误,我无法理解(看起来应该很简单)。当我尝试创建以下表达式时:

def FindLabel ( [FacilityName] ):
  S = [FacilityName] 
  S = S.upper()
  return S
我返回一个错误,如下所示:

Error 0 on line 0.
Error running expression:  FindLabel(ESRIExpressionArg0)
Traceback (most recent call last):
 File "<expression>", line 1, in <module>
 File "<string>", line 3, in FindLabel
AttributeError: 'NoneType' object has no attribute 'upper'.
第0行出现
错误0。
运行表达式时出错:FindLabel(ESRIExpressionArg0)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
FindLabel中第3行的文件“”
AttributeError:“非类型”对象没有属性“上限”。
[FacilityName]是域字段,允许使用空值。我理解,我认为,'NoneType'意味着[FacilityName]在试图返回之前被赋予一个None值,但我不知道如何解决这个问题

谢谢


Ethan

我很确定所有的值都以字符串的形式返回,但是在空值的情况下,它可能会以
None
的形式返回,这可以解释出现的错误

您可以使用
try..except
块或在函数中使用条件语句忽略
None

这里有
try..except

def FindLabel ( [FacilityName] ):
    try:
        S = [FacilityName] 
        S = S.upper()
        return S
    except AttributeError:
        pass

是的,这解决了问题,谢谢!我认为,当ArcMap检查表达式时,由于某些点的FacilityName值为null,而不是字符串,因此返回了错误。