Misleading IOerror when opening a non-existent file for append?

paul.keating at nibc.com paul.keating at nibc.com
Mon Nov 20 10:47:56 EST 2006


It probably is misleading. But I'd say it's a misleading Linux message
not a misleading Python message.
f = file(r'c:\temp\DoesNotExist.txt','a')
not only does not give a misleading error under Windows, it works.

It appears that under Linux if you open a file for writing, but specify
append, it complains about the append if there isn't a file to append
to (a reasonable complaint, IMO).

> >>> ifile=open("\\no_such_dir\\no_such_file" ,'a')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> IOError: invalid mode: a

> >>> ifile=open("\\no_such_dir\\no_such_file" ,'r')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> IOError: [Errno 2] No such file or directory:




More information about the Python-list mailing list