thanks, luke, Andre.
appreciate it a lot
shawn
On 1/3/07, Andre Roberge <[EMAIL PROTECTED]> wrote:
On 1/4/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
>
> shawn bright wrote:
> > hello there,
> > i am writing an app for linux. what command would be easiest to test
> > and see if a certain file exist ?
> > i was going to do something like this
> > try:
> > file = open('/path/to/file', 'rb')
> > return True
> > except:
> > return False
> You should except IOError here, just to be clear and such.
> >
> > but i thought that there would be an easier way.
> The os module has some function for checking if files exist, I think.
Yes, check out access():
http://docs.python.org/lib/os-file-dir.html
André
Or you could do
> if targetfile not in os.listdir(directory): return False
> else: return True
>
> But your original solution is okay.
> HTH,
> -Luke
> _______________________________________________
> Tutor maillist - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor