Misleading IOerror when opening a non-existent file for append?
Rob Williscroft
rtw at freenet.co.uk
Mon Nov 20 11:08:00 EST 2006
paul.keating at nibc.com wrote in news:1164037676.537263.53480
@f16g2000cwb.googlegroups.com in comp.lang.python:
> 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.
AFAICT that wasn't quite what the OP was trying to do, more like:
>>> f = file(r'c:\does-not-exist\DoesNotExist.txt','a')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
f = file(r'c:\does-not-exist\DoesNotExist.txt','a')
IOError: [Errno 2] No such file or directory: 'c:\\does-not-exist
\\DoesNotExist.txt'
>>>
So at least the error messsage is better.
But I'm confused by the use of '\\' by the OP on *nix this should
be just a character in the filename so in /home/username
file=open("\\no_such_dir\\no_such_file" ,'a')
whould be attempting to append to the (presumably) non-existant
file /home/username/\\no_such_dir\\no_such_file
Perhaps the append mode ('a') doens't create a file on the OP's
linux box, and thus using 'a' for a file name that doesn't exist
is an "invalid mode".
Rob.
--
http://www.victim-prime.dsl.pipex.com/
More information about the Python-list
mailing list