Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我试着比较int和func,它给出了一个错误_Python - Fatal编程技术网

Python 我试着比较int和func,它给出了一个错误

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

我试图比较函数和整数,但它给出了一个错误 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.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'