Python声明的全局类列表正在创建错误:未定义的全局名称...未定义
我在Python类的全球空间中宣布了列表。我将其导入另一个使用Arcpy的类,并且我会收到错误:未定义的全局名称'TargetFieldNames'。我尝试使用值(TargetFieldNames = ['junk'])
初始化列表。我已经尝试将所有全局列表放入__ INIT __。
时,当我评论targetFieldNames时,错误会切换到我的dbug = dbug()
line。
这是代码:
import arcpy
from dbug import DBug # My own debug class
class FieldMill:
# Set up the class level stuffs
baseFieldNames = []
targetFieldNames = []
fieldsToCorrect = []
# Call in our own logger
dBug = DBug()
# Separate the list into two: the base (properly named) fields
# and the target (suspectly named) fields.
def make_cases_match( self, fieldList ):
for f in fieldList:
if not f.required:
if f.name.endswith( '_1' ):
#baseFields.append( f )
strippedName = f.name.replace( '_1', "" ) # Can't match with '_1'
baseFieldNames.append( strippedName )
else:
#targetField.append( f )
targetFieldNames.append( f.name )
# These lines added for debug
dBug.printMessage("\n##### HERE IS WHAT baseFieldNames GOT:")
dBug.printMessage( baseFieldNames )
dBug.printMessage("\n##### HERE IS WHAT targetFieldNames GOT:")
dBug.printMessage( targetFieldNames )
I have declared lists in the global space of a python class. I import it into another class that uses Arcpy, and I get the error: global name 'targetFieldNames' is not defined. I have tried initializing the list with a value (targetFieldNames = ['junk'])
. I have tried putting all the global lists in an __init__.
When I comment out the targetFieldNames, the error switches to my dBug = DBug()
line.
Here is the code:
import arcpy
from dbug import DBug # My own debug class
class FieldMill:
# Set up the class level stuffs
baseFieldNames = []
targetFieldNames = []
fieldsToCorrect = []
# Call in our own logger
dBug = DBug()
# Separate the list into two: the base (properly named) fields
# and the target (suspectly named) fields.
def make_cases_match( self, fieldList ):
for f in fieldList:
if not f.required:
if f.name.endswith( '_1' ):
#baseFields.append( f )
strippedName = f.name.replace( '_1', "" ) # Can't match with '_1'
baseFieldNames.append( strippedName )
else:
#targetField.append( f )
targetFieldNames.append( f.name )
# These lines added for debug
dBug.printMessage("\n##### HERE IS WHAT baseFieldNames GOT:")
dBug.printMessage( baseFieldNames )
dBug.printMessage("\n##### HERE IS WHAT targetFieldNames GOT:")
dBug.printMessage( targetFieldNames )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定使用自己应该解决您的问题,
这对您有用吗?
I’m pretty sure using self should fix your issue
Would this work for you?