Search code examples
iomodepython-3.4

Python 3.4 open(file, 'a') aifc.Error


I'm using Netbeans to write python, and I had it so that I could append a file (in Eclipse) with file = open('dir\file', 'a') so I could append a file, but I get this:

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

I don't want to have to read the file, save either to array or temp file and then rewrite. What's going on?

Note: I get the same thing in Command Prompt, which seems weird to me.

Also, I know my interpreter is configured properly and everything is in the python34 folder (namely python34\Lib\site-packages)

Full error message on run:

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'

Solution

  • That error is coming from the aifc module. aifc.open only supports the r, rb, w, and wb modes. Are you calling from aifc import * somewhere in your script? If so, don't do that! It's shadowing the built-in open with aifc.open. Only import the functions you need from aifc.