Python:TypeError:“str”对象不是可调用的分级系统

2024-09-30 01:18:44 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行此代码时:

def printPredictions(matches):
    pPredictionTable = PrettyTable()
    pPredictionTable.field_names = ["Player 1", "Player 2", "Difference", "Winner"]
    for match in matches:
        p1 = match['teamA']
        p2 = match['teamB']
        if match['aBeatb'] == True:
            pPredictionTable.add_row([match['teamA'], match['teamB'], match['difference'], p1])             
        else:
            pPredictionTable.add_row([match['teamA'], match['teamB'], match['difference'], p2])

    print(pPredictionTable)    

printPredictions(pmatches)

我得到这个错误:

Traceback (most recent call last):
  File "C:\Users\ericr_000\Desktop\PyDev\NPA-2-Rating-System\Rankings.py", line 645, in <module>
    printPredictions()
TypeError: 'str' object is not callable

我有pmatches作为一个单独的字典,我没有编码技能来解决这个问题。(第145行是printPredictions(pmatches)


Tags: 代码inaddmatchrowplayerp2matches
1条回答
网友
1楼 · 发布于 2024-09-30 01:18:44

如果您在尝试调用printPredictions时得到'str' object is not callable,这意味着当程序到达第645行时,printPredictions的名称被重新分配给一个字符串。在代码的某个地方

printPredictions = someStringValueGoesHere

您应该为该变量选择一个不同的名称,或者完全删除该行。你知道吗

foobar = someStringValueGoesHere

相关问题 更多 >

    热门问题