繁体   English   中英

TypeError: an integer is required (got type str), 一个高分保存功能

[英]TypeError: an integer is required (got type str), A high score saving function

我目前正在尝试创建一个从文件读取和写入的高分保存功能。

self.dir = path.dirname(__file__)
with open(path.join(self.dir),Highscore_File,"w") as f:
        f.write((self.score))

我得到的错误是:

TypeError: an integer is required (got type str)

我曾尝试将self.dir转换为整数,但遇到了更复杂的错误。

open(path.join(self.dir), Highscore_File, "w")

应该

open(path.join(self.dir, Highscore_File), "w")

错误是因为您错误地将 3 个参数传递给open而第三个参数预计为整数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM