Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

get_exec_path
unix
python programming
communitycreator

What is os.get_exec_path() in Unix using Python?

AKASH BAJWA

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The method get_exec_path() is from the OS module and extracts the list of directories. While launching a process, these directories will be searched for the named executable.

Note: The OS module in Python directly helps to deal with operating system features.

Syntax


os.get_exec_path(env=None)

Parameters

This method accepts a single argument:

  • env (default=None): This is the dictionary of environment variables. When env is set to None, environ is used.

Note: environ is a mapping object which contains user environmental variables.

Return value

get_exec_path() returns a list containing paths of directories.

Exception

OSError: This error is raised when a system related error comes.

Explanation

Now, let’s discuss some examples related to this method:

# Case#1 Default path testing
# importing os module 
import os
# Extracting path
executable_path = os.get_exec_path()
# Print the path list of current process
print("Current Executable path list: ")
print(executable_path)

Case #1

  • Line 5: We fetch the list of directories that is used to search a named executable.
  • Line 8: We print a list of paths.

Case #2

  • Line 5: We have the dictionary instance of the user-defined path.
  • Line 8: We fetch the list of directories that is used to search a named executable according to env.
  • Line 11: We print a list of paths.

RELATED TAGS

get_exec_path
unix
python programming
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring