Python equivalent to 'which'?

Michael Gilfix mgilfix at eecs.tufts.edu
Tue Jul 30 13:21:24 EDT 2002


  Seems like that might make a good convenience function in the
os.path module. I'm sure many people have wanted such a function
if they're using python for pure scripting. Perhaps you should try
submitting a short patch...? Worst case, at least it'll get stored in
the system.

                    -- Mike

On Tue, Jul 30 @ 10:01, Sean 'Shaleh' Perry wrote:
> >>> def which(exe):
> ...   for d in string.split(os.getenv('PATH'), ':'):
> ...     name = os.path.join(d, exe)
> ...     if os.path.isfile(name): return name
> ...   return None
> ... 
> >>> which('bash')
> '/bin/bash'
> >>> which('foo')
> that's all 'which' does (-:

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html




More information about the Python-list mailing list