我正在使用 Netbeans 编写 python,我有了它,这样我就可以附加一个文件(在 Eclipse 中) file = open('dir\file', 'a') 所以我可以附加一个文件,但我得到这个:

aifc.Error: mode must be 'r', 'rb', 'w', or 'wb'

我不想读取文件,保存到数组或临时文件,然后重写。这是怎么回事?

笔记:我在命令提示符中得到了同样的结果,这对我来说似乎很奇怪。

另外,我知道我的解释器配置正确,所有内容都在 python34 文件夹中(即 python34\Lib\site-packages)

运行时的完整错误消息:

Running...
Traceback (most recent call last):
  File "G:\Prog\PythonCurrent\RadioDB\src\radiodb.py", line 122, in <module>
    main()
  File "G:\Prog\PythonCurrent\RadioDB\src\radiodb.py", line 43, in main
    lineTypesFile = open('{}/Desktop/GPS Line Types.txt'.format(home), 'a')
  File "c:\Python34\lib\aifc.py", line 891, in open
    raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
aifc.Error: mode must be 'r', 'rb', 'w', or 'wb'
有帮助吗?

解决方案

该错误来自 aifc 模块。 aifc.open 只支持 r, rb, w, , 和 wb 模式。你打电话吗 from aifc import * 你的脚本中的某个地方?如果是这样,请不要这样做!它遮盖了内置的 openaifc.open. 。只导入你需要的函数 aifc.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top