> Date: Sun, 1 Aug 2010 12:28:49 -0700 > From: "Richard D. Moores" <rdmoo...@gmail.com> > To: pyt...@bdurham.com > Cc: tutor@python.org > Subject: Re: [Tutor] How to get script to detect whether a file > exists? > Message-ID: > <aanlktintoakh1ag-jptw2ybmzdh9fjrq5ohfp7qn5...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > On Sun, Aug 1, 2010 at 11:33, <pyt...@bdurham.com> wrote: > > Richard, > > > > Look at the os.path.isfile function. > > > > Malcolm > > Thanks, Malcolm. That makes a tremendous difference. > > If anyone's curious, they see what use I've made of > os.path.isfile(path): <http://tutoree7.pastebin.com/39kXSEjb> > > Dick > > > > > > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 78, Issue 8 > ************************************ >
I don't know if I am right, but I remember reading it is better to try to open the files and see if an exception is raised than checking if the files exist. In that way one can avoid TOCTTOU bugs ( http://en.wikipedia.org/wiki/Time-of-check-to-time-of-use ) Without knowing what your code does, I think it will be something like: try: F_unused = open(path1, 'rb') F_used = open(path2, 'rb') except IOError: print("no") ..... else: unused_ints = pickle.load(F_unused) ...... HTH Daniel Sarmiento S.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor