Python 我试着比较int和func,它给出了一个错误
我试图比较函数和整数,但它给出了一个错误 my game.py:Python 我试着比较int和func,它给出了一个错误,python,Python,我试图比较函数和整数,但它给出了一个错误 my game.py: def game(): return 64 score = game() with open("hiscore.txt" , "r") as f: hiscore = int(f.read) if hiscore<score : with open("hiscore.txt" , "r") as f: f.wri
def game():
return 64
score = game()
with open("hiscore.txt" , "r") as f:
hiscore = int(f.read)
if hiscore<score :
with open("hiscore.txt" , "r") as f:
f.write(str(score))
你错过了()
之后的f.read
int(f.read())
感谢您在以下代码中指出写入文件时的错误模式
以open(“hiscore.txt”、“r”)作为f的:
f、 写(str(分数))
您应该将写入文件的模式从打开(“hiscore.txt”,“r”)
更改为“w”
或“a”
:读取文件的内容“r”
:覆盖任何现有内容“w”
:将附加到行的末尾“a”
hiscore = int(f.read)
TypeError: int() argument must be a string, a bytes-like object or a number, not
'builtin_function_or_method'