Python Glossary Русский

Python 3.2+osfunction

os.get_exec_path

os — environment

Return the list of directories searched for executables (from PATH).

Syntax

os.get_exec_path()

It reads PATH from os.environ at call time, or from an env mapping you pass — useful to see where a child with a different environment will look for programs. Empty PATH entries and the current directory are not filtered out. To find a specific program you need not search by hand: shutil.which does it, including Windows extensions.

Examples

import os
print(os.get_exec_path({'PATH': os.pathsep.join(['/usr/bin', '/bin'])}))   # → ['/usr/bin', '/bin']
print(os.get_exec_path() == os.environ['PATH'].split(os.pathsep))   # → True — это просто PATH, разбитый по os.pathsep
print(os.get_exec_path({'PATH': ''}))   # → [''] — пустой PATH даёт один пустой элемент, то есть текущий каталог
print(os.get_exec_path({}))   # → если ключа PATH нет, берётся os.defpath: на Linux ['/bin', '/usr/bin']

See also

Open in the full glossarydocs.python.orgReport an inaccuracy