代码import reletters = ["x","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"]def coordSplit(coord): splitCoord=[] match = re.match(r"([A-Z]+)([0-9]+)", coord, re.I) if match: splitCoord = match.groups() count=0 for letter in letters: if splitCoord[0] == letter: print(splitCoord[0]) splitCoord[1] = str(count) #it can not change this value to a number NameError: name xxx is not defined count = count + 1 return splitCoordlocation = "H6"coordSplit(location)我一直在把它放在一起,但我一直收到错误“NameError:name splitCoord is not defined”和“'tuple' object does not support item assignment”任何人都可以帮忙
1 回答
炎炎设计
TA贡献1808条经验 获得超4个赞
这一行:
splitCoord = match.groups()
返回一个元组。
因此这一行:
splitCoord[1] = str(count)
不会工作,因为元组是不可变的。
使用:
splitCoord = list(match.groups())
添加回答
举报
0/150
提交
取消