portable way of locating an executable (like which)

Ramchandra Apte maniandram01 at gmail.com
Sat Sep 22 23:55:46 EDT 2012


On Friday, 21 September 2012 02:37:01 UTC+5:30, gelonida  wrote:
> I'd like to implement the equivalent functionality of the unix command
> 
> /usr/bin/which
> 
> 
> 
> The function should work under Linux and under windows.
> 
> 
> 
> Did anybody already implement such a function.
> 
> If not, is there a portable way of splitting the environment variable PATH?
> 
> 
> 
> Thanks for any sugestions

shutil.which does this in Python 3.3: http://docs.python.org/dev/library/shutil.html#shutil.which
You can copy the code to support older Python versions.



More information about the Python-list mailing list