Python:TypeError:不支持“int”和“int”的操作数类型

2024-07-02 13:41:50 发布

您现在位置: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), matchObj.group(3), matchObj.group(4)]

然后我调用analyzeHeader:

^{pr2}$

如果我把上面的行改成:

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"

你知道这个代码有什么问题吗?在


Tags: import功能rereturndefmatchgroupcol
1条回答
网友
1楼 · 发布于 2024-07-02 13:41:50

代码没有问题。我用来执行代码的工具只是覆盖了Python最初的int()函数。然后我要做的就是调用原始的int()函数:__builtin__.int()

相关问题 更多 >