Ben Finney wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
>
> > You could try to read the file, if that fails it doesn't exist:
> >
> > try:
> >     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.
>
Ok, true. You can test explicit on non existence as follows, and then
decide to open the file

import errno
try:
    f = open('xxx')
except IOError, e:
    if e.errno == errno.ENOENT:
        f = open('xxx', 'w')
print f

> --
>  \            "If you continue running Windows, your system may become |
>   `\                 unstable."  -- Microsoft, Windows 95 BSOD message |
> _o__)                                                                  |
> Ben Finney

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to