best way to check if a file exists?
bignose+hates-spam at benfinney.id.au
Wed Nov 1 15:00:53 CET 2006
"wittempj at hotmail.com" <martin.witte at gmail.com> writes:
> You could try to read the file, if that fails it doesn't exist:
> f = open('xxx')
> except IOError:
> f = open('xxx', 'w')
> print "file doesn't exist"
> print f
Except that there are other conditions than "File doesn't exist" that
can cause an 'open' to fail.
\ "If you continue running Windows, your system may become |
`\ unstable." -- Microsoft, Windows 95 BSOD message |
More information about the Python-list