Skip to content

Which

which(name, all=False)

which(name, flags = os.X_OK, all = False) -> str or str set

Works as the system command which; searches $PATH for name and returns a full path if found.

If all is :const:True the set of all found locations is returned, else the first occurrence or :const:None is returned.

Parameters:

Name Type Description Default
`name` str

The file to search for.

required
`all` bool

Whether to return all locations where name was found.

required

Returns:

Type Description
Set[str] | str | None

If all is :const:True the set of all locations where name was found,

Set[str] | str | None

else the first location or :const:None if not found.

Example

which('sh') '/bin/sh'