Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

learn if program is installed from Python

Name: Anonymous 2008-01-07 20:40

I just ran a small Python script of mine on a new computer and I got an error message that xsltproc isn't found. So I want to modify the script to test whether xsltproc is installed. (I should probably do this with several other scripts too.)

However, I don't know how to do this. How do I learn, from a Python script running on Linux, whether a program is installed?

Name: Anonymous 2008-01-07 21:55

>>4 You mean split $PATH by os.pathsep and look in each dir.

In code,

import os
f = 'xsltproc'
for d in os.environ.get('PATH', os.defpath).split(os.pathsep):
    path = os.path.join(d, f)
    if os.path.exists(path):
        break
else:
    path = None
print path or 'Not found.'

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List