best way of testing a program exists before using it?
Hari Sekhon
hpsekhon at googlemail.com
Tue Sep 12 08:30:47 EDT 2006
Tim Williams wrote:
> Alternatively there is os.path.exists which works for files or
> directories, but calling it every time you use the wrapper is probably
> more expensive than using the try statement when the program *does*
> exist.
>
> import os.path
> if not os.path.exists('/dir1/dir2/filename'):
> print_something_and_exit(filename)
>
> :)
>
problem with that is that the path may change between installations on
different machine and I can't guarantee /dir1/dir2 which is why a test
of all dirs in the path is more portable.
--
Hari Sekhon
More information about the Python-list
mailing list