Platform independent whereis function I'm trying to write a platform independent Python (>=3.6.5) package that has a handful of java .class files that need to compiled using javac and run using java. This is simple enough task but I need to know if user has these installed already and the location of the executable assuming that neither of them is on the system path. That way I can just call the executable by it's path using subprocess.run. Which bring me to the subject of this review a platform independent whereis command.



import os, subprocess
from subprocess import CalledProcessError


def whereis(app):
    """Return a list of locations a given application.

    Relies on the `where` system command in Windows and the `whereis` command in Unix.

    Parameters
    ----------
    app : str
        Can be any application on the system path e.g. java.

    Returns
    -------
    result : list
        A list of locations where applications is installed.

    Useage
    ------
    &gt;&gt;&gt;whereis('javac')
    'C:\\Program Files\\Java\\jdk1.8.0_162\\bin\\javac.exe'
    """

    result = None

    if os.name == "nt":# Windows
        try:
            result = subprocess.check_output("where {}".format(app))

        except CalledProcessError as err:
            print("Application ,",app,", not forund.",err)

    else:# Unix
        try:
            result = subprocess.check_output("whereis {}".format(app))

        except CalledProcessError as err:
            print("Application ,",app,", not found.",err)

    if result is None:
        print("")
        result = []
        return result

    else:
        result = result.decode().replace("\r", "").split("\n")
        result = list(filter(lambda x: len(x)&gt;0, result))
        return result


Questions


Is there a standard library function that already covers this? I couldn't find one but that doesn't mean anything.
Are there any caveats or edge cases that I'm missing?
Can any general improvements be made to the code or docstring?
A couple of small things:


If you're specifically looking for executable files, you might use which instead of whereis command. From this answer, you can see the difference between the two using whatis:


$  whatis which
which                (1)  - shows the full path of (shell) commands

$  whatis whereis
whereis              (1)  - locate the binary, source, and manual page files for a command


Be consistent. You've used two different formatting styles:

"where {}".format(app)


and

"Application ,",app,", not forund.",err  # you also have a spelling mistake here (forund -&gt; found) 


I'd recommend you use the former one
You should have at least two spaces before an inline comment
You should put a space after the comma in almost every situation. (e.g: print("Application,",app,", not found.",err) -> print("Application,", app, ", not found.", err))