PyDocs

Nav

File and Directory Access

which

shutil

function · Added in 3.3 (source)
  • which(cmd, mode=os.F_OK | os.X_OK, path=None)
Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.

`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
of os.environ.get("PATH"), or can be overridden with a custom search
path.
Changed in 3.8, 3.12
  • 3.8: The bytes type is now accepted. If cmd type is bytes, the result type is also bytes.
  • 3.12: On Windows, the current directory is no longer prepended to the search path if mode includes os.X_OK and WinAPI NeedCurrentDirectoryForExePathW(cmd) is false, else the current directory is prepended even if it is already in the search path; PATHEXT is used now even when cmd includes a directory component or ends with an extension that is in PATHEXT; and filenames that have no extension can now be found.
1 Example
>>> shutil.which("python")
'C:\\Python33\\python.EXE'
from the Python docs
See Also
No see-alsos for shutil/which
0 Notes
No notes for which