How does Python handle probing to see if a file already exists?

Skip Montanaro skip at pobox.com
Tue Nov 5 13:54:09 EST 2002


    gustavo> Others have talked about the goodness of using try/except, I'll
    gustavo> say to use os.access(), which is precisely for what you're
    gustavo> asking, if you can read or write a file.

os.access() is almost never what you want.  On Unix systems, if you are su'd
to another user it tests permissions using the wrong user (real instead of
effective).  Just try the operation and recover if it throws an exception.

-- 
Skip Montanaro - skip at pobox.com
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list