写入二进制文件时的无效参数

2024-09-30 14:21:45 发布

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

我尝试使用pickle从二进制文件中读取,调整其内容,然后用新的更新字典覆盖二进制文件的内容。 但是,我收到以下错误:

startHandCountFile = open("startHandCount", 'wb') OSError: [Errno 22] Invalid argument: 'startHandCount'.

我目前的理解是,它应该可以工作,因为文件与正在运行的python文件位于同一个目录中,并且我已经检查了我没有错过拼写该文件。在

我的代码:

    startHandCountFile = open("startHandCount", "rb")
    self.startHandCount = pickle.load(startHandCountFile)
    self.currentStartHandCount = self.startHandCount
    self.startHandCount[startingTotal][1] += 1
    print("print still working")
    startHandCountFile.close()

    startHandCountFile = open("startHandCount", 'wb')
    pickle.dump(self.currentStartHandCount, startHandCountFile)
    startHandCountFile.close()

谢谢你的帮助。在


Tags: 文件self内容close字典错误二进制open