Python equivalent to 'which'?
Sean 'Shaleh' Perry
shalehperry at attbi.com
Tue Jul 30 13:01:23 EDT 2002
On 30-Jul-2002 eg wrote:
> Is their a python equivalent to the bash shell command 'which'? I
> haven't found it, and 'which' is such a common word that it may be
> lost in the noise in my dejanews searches :(
>
> I could grab the PATH environment variable and walk all the paths, but
> I'm hoping python has already done it for me!
> Thanks
> Eric
> --
> http://mail.python.org/mailman/listinfo/python-list
>>> 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 (-:
More information about the Python-list
mailing list