写入二进制文件时参数无效
Invalid argument when writing to a binary file
我正在尝试使用 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()
感谢您的帮助。
尝试 运行 我的程序在我的 dropbox 之外和位于我硬盘驱动器上的目录中,这解决了我遇到的错误。
我正在尝试使用 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()
感谢您的帮助。
尝试 运行 我的程序在我的 dropbox 之外和位于我硬盘驱动器上的目录中,这解决了我遇到的错误。