Python:TypeError:-:';int';和';int';
这是我的一个功能:Python:TypeError:-:';int';和';int';,python,Python,这是我的一个功能: def analyzeHeader(headerLine): import re matchObj = re.match("^\s*(\w+).+:\s*(\d+)\s+Name = (.+) - Type = (.+)\s*$", headerLine, re.M|re.I) if not matchObj: return None return [matchObj.group(1), matchObj.group(2), m
def analyzeHeader(headerLine):
import re
matchObj = re.match("^\s*(\w+).+:\s*(\d+)\s+Name = (.+) - Type = (.+)\s*$", headerLine, re.M|re.I)
if not matchObj:
return None
return [matchObj.group(1), matchObj.group(2), matchObj.group(3), matchObj.group(4)]
然后我调用analyzeHeader:
list = analyzeHeader(headerLine)
## ....
col = int(float(list[1])) - 1 ### <== Error here
list=analyzeHeader(headerLine)
## ....
col=int(float(list[1])-1####代码没有问题。我用来执行代码的工具只涉及Python的原始int()函数。然后我所要做的就是调用原始的int()函数:\uuuu builtin\uuuu.int()
请输入完整的错误输出,因为我无法再现错误;您是否将int()
的子类重新分配给了int
可能?考虑到您所做的:list=analyzeHeader(headerLine)
您可能将int
类型替换为其他类型。定义用户类/对象/变量时不要使用内置名称!
list = analyzeHeader(headerLine)
## ....
col = float(list[1]) - 1 ### <== OK now
c = int(col)
r = row - 1
tmp = data[r]
res = float(tmp[c]) ### Error now occurs here: "TypeError: list indices must be integers"