Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.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
Python 比较字符串会导致运行时错误_Python - Fatal编程技术网

Python 比较字符串会导致运行时错误

Python 比较字符串会导致运行时错误,python,Python,我正在比较脚本中作为字符串存储的两个GUI,这会导致运行时错误。如果我更改If语句,它会将运行时错误推送到父for循环。我可以在IF语句上方添加一个显然无用的for循环,然后它似乎可以修复运行时错误 以下是遇到错误的初始代码: for row in cursor: print 'Remote len: '+str(len(agoFeatures)) for agoFeature in agoFeatures: print 'row[2]: ', row[2], t

我正在比较脚本中作为字符串存储的两个GUI,这会导致运行时错误。如果我更改If语句,它会将运行时错误推送到父for循环。我可以在IF语句上方添加一个显然无用的for循环,然后它似乎可以修复运行时错误

以下是遇到错误的初始代码:

for row in cursor:
    print 'Remote len: '+str(len(agoFeatures))
    for agoFeature in agoFeatures:
        print 'row[2]: ', row[2], type(row[2]), len(row[2])
        print "agoFeature[a][s]: ", \
              agoFeatures['attributes']['SegmentID'].upper(), \
              type(agoFeature['attributes']['SegmentID'].upper()), \
              len(agoFeature['attributes']['SegmentID'].upper())
        localFeature = row[2]
        remoteFeature = '{'+agoFeature['attributes']['SegmentID'].upper()+'}'

        print 'localFeature: ', localFeature, type(localFeature), len(localFeature)
        print 'remoteFeature: ', remoteFeature, type(remoteFeature), len(remoteFeature)

        if localFeature == remoteFeature:
            print 'Local == Remote'
运行时,它将返回以下内容:

远程镜头:2
第[2]行:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
agoFeature[a][s]:ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD 36
本地功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
远程功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
本地==远程
第[2]行:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
agoFeature[a][s]:714215DE-7E54-4E3E-8078-3C90E5407237 36
本地功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
远程功能:{714215DE-7E54-4E3E-8078-3C90E5407237}38
遥控镜头:2
第[2]行:{714215DE-7E54-4E3E-8078-3C90E5407237}38
agoFeature[a][s]:ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD 36
localFeature:{714215DE-7E54-4E3E-8078-3C90E5407237}38
远程功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
回溯(最近一次呼叫最后一次):
文件“GetUpdates.py”,第262行,在
main()
文件“GetUpdates.py”,第248行,在main中
compareAGOFeaturesToLocal()
文件“GetUpdates.py”,第147行,与AturateAstofLocal进行比较
如果localFeature==remoteFeature:
访问违例
这将比较两个guid,并在第三次比较(7142与ED24)后在IF语句上崩溃。如果我将If语句更改为以下内容,它将一直持续到结尾(7142对7142),但会在for循环中崩溃

if str(localFeature) == str(remoteFeature):
    print 'Local == Remote'
结果:

远程镜头:2
第[2]行:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
agoFeature[a][s]:ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD 36
本地功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
远程功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
本地==远程
第[2]行:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
agoFeature[a][s]:714215DE-7E54-4E3E-8078-3C90E5407237 36
本地功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
远程功能:{714215DE-7E54-4E3E-8078-3C90E5407237}38
遥控镜头:2
第[2]行:{714215DE-7E54-4E3E-8078-3C90E5407237}38
agoFeature[a][s]:ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD 36
localFeature:{714215DE-7E54-4E3E-8078-3C90E5407237}38
远程功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
第[2]行:{714215DE-7E54-4E3E-8078-3C90E5407237}38
agoFeature[a][s]:714215DE-7E54-4E3E-8078-3C90E5407237 36
localFeature:{714215DE-7E54-4E3E-8078-3C90E5407237}38
远程功能:{714215DE-7E54-4E3E-8078-3C90E5407237}38
本地==远程
回溯(最近一次呼叫最后一次):
文件“GetUpdates.py”,第262行,在
main()
文件“GetUpdates.py”,第248行,在main中
compareAGOFeaturesToLocal()
文件“GetUpdates.py”,第137行,与属性本地的比较
对于agoFeatures中的agoFeature:
访问违例
我认为文本中有某种东西引起了问题。我从IF语句中删除了str,并添加了一个for循环来打印remoteFeature中的每个字符

for row in cursor:
    print 'Remote len: '+str(len(agoFeatures))
    for agoFeature in agoFeatures:
        print 'row[2]: ', row[2], type(row[2]), len(row[2])
        print "agoFeature[a][s]: ", \
              agoFeatures['attributes']['SegmentID'].upper(), \
              type(agoFeature['attributes']['SegmentID'].upper()), \
              len(agoFeature['attributes']['SegmentID'].upper())
        localFeature = row[2]
        remoteFeature = '{'+agoFeature['attributes']['SegmentID'].upper()+'}'

        print 'localFeature: ', localFeature, type(localFeature), len(localFeature)
        print 'remoteFeature: ', remoteFeature, type(remoteFeature), len(remoteFeature)

        for i, char in enumerate(remoteFeature):
                i, ord(char), char

        if localFeature == remoteFeature:
            print 'Local == Remote'
我删除了print语句,因为它不打印任何有用的内容(只显示每个期望的字符)。添加的for循环不执行任何操作,但允许它成功完成:

远程镜头:2
第[2]行:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
agoFeature[a][s]:ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD 36
本地功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
远程功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
本地==远程
第[2]行:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
agoFeature[a][s]:714215DE-7E54-4E3E-8078-3C90E5407237 36
本地功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
远程功能:{714215DE-7E54-4E3E-8078-3C90E5407237}38
遥控镜头:2
第[2]行:{714215DE-7E54-4E3E-8078-3C90E5407237}38
agoFeature[a][s]:ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD 36
localFeature:{714215DE-7E54-4E3E-8078-3C90E5407237}38
远程功能:{ED24C58B-253F-4D8A-8C1E-EBFFC57B4FDD}38
第[2]行:{714215DE-7E54-4E3E-8078-3C90E5407237}38
agoFeature[a][s]:714215DE-7E54-4E3E-8078-3C90E5407237 36
localFeature:{714215DE-7E54-4E3E-8078-3C90E5407237}38
远程功能:{714215DE-7E54-4E3E-8078-3C90E5407237}38
本地==远程
开始时间:2014-08-1411:41:20.628000
完:2014-08-1411:41:24.685000
差额:0:00:04.057000

打印开始/结束/差异在脚本末尾处理。你知道为什么会发生这个错误吗,或者我如何处理它?我不喜欢额外的for循环,因为它是一种黑客行为。

原始for循环中的游标对象是使用arcpy(ArcGIS 10.2.2 python库:)从SearchCursor创建的

当我从光标打印行时,我得到以下值:

(None, 1007, u'{714215DE-7E54-4E3E-8078-3C90E5407237}', <nil>)
(无,1007,u'{714215DE-7E54-4E3E-8078-3C90E5407237},)
Shape@JSON返回导致错误的
。虽然我没有与元组中的nil值进行交互,但这是导致问题的原因。如果我确实通过打印第[3]行与它进行交互,它将导致python崩溃


问题是来自第三方软件包的错误数据。

您是否截断了回溯错误消息,当您收到运行时错误时,它通常不仅仅表示错误。这是一个奇怪的错误,您没有理由需要破解它。我想知道你的Python安装是否在某种程度上搞砸了。有可能在另一台电脑上试用吗?我刚刚在另一台电脑上试用过,一台是Windows 8,另一台是Windows 8.1,它运行相同的程序(崩溃)。两者都是Python2.7.5。我需要使用这个版本,这样我就可以使用ArcGIS(arcpy)库了。我不认为是arcpy库,因为变量的类型是unicode,它只是做一个基本的比较。如果你能想出一个对你来说失败的SSCCE(),它将极大地增加我们能够找出什么是
(None, 1007, u'{714215DE-7E54-4E3E-8078-3C90E5407237}', <nil>)