reqhye72zux at mailexpire.com
Thu Oct 18 16:37:04 CEST 2001
Rikard Bosnjakovic wrote:
> Alec D. Cheah wrote:
>> How do verified from input the variable entered is a file or a
>> path and how do you check whether it exist or not??
>> Newbie on Python....
> >>> import os
> >>> s = "/tmp/foobar" os.stat(s)
> I.e., you should enclose the stat() within a try-except in case the
> file does not exist.
That's doing it the hard way. Try
os.path.exists("your suspected file here")
if that doesn't return 0, use
os.path.isfile("your suspected file here")
os.path.isdir("your suspected file here")
To find out if it's a file or a directory. If you do *any* path
manipulations you'll do yourself a favour by reading the docs on the
More information about the Python-list