Python OS MODULE : os.getenvb() , os.get_exec_path()














































Python OS MODULE : os.getenvb() , os.get_exec_path()



 
                                              OS MODULE METHOD

  • os.getenvb(key, default=None)

               os.getenvb() method is a bytes version of os.getenv() method. This function of os module also returns the value of the environment variable correlated with specified key. But contrasting os.getenv() method, it accepts a bytes object as the key and returns a bytes object as the value of the environment variable.

Syntax:

os.getenvb(key, default = None)

Parameters:
key: It is a  bytes object which is denoting the name of environment variable.
default (optional) : It is a string denoting the default value in case if key does not exists. It's   default value is "None".

Return Type:

This function returns a bytes object which signify the value of the environment variable. In case if key does not exists it returns the value of default parameter.

Example:-


Output:-
Value of 'HOME' environment variable : b'/home/hp'
Value of 'JAVA_HOME' environment variable : b'/documenst/jdk-10.0.1'

  • os.get_exec_path(env=None)
                os.get_exec_path() function is used to get the list of directories that will be searched for a named executable while launching a process.

Syntax:

os.get_exec_path(env = None)

Parameter:
env(optional): A dictionary representing the environment variables. The default value of this parameter is None.

Use of os.get_exec_path() method:-


Output:-

Following paths will be searched for a named executable:
['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/usr/games', '/usr/local/games', '/snap/bin', '/usr/local/java/jdk-10.0.1/bin', '/usr/local/java/jdk-10.0.1/jre/bin']

Specifying env parameter:-


Output:-

Following paths will be searched for a named executable:
['', '/bin', '/usr/bin']


More Articles of shobha dhande:

Name Views Likes
Python OS.PATH Module os.path.normcase() Method 370 0
Python OS.PATH Module os.path.exists() Method 592 1
Python OS.PATH MODULE os.path.lexists() Method 296 1
Python OS.PATH MODULE os.path.samestat() Method 325 1
Python OS.PATH MODULE os.path.getsize() Method 402 1
Python OS..PATH MODULE os.path.getctime() Method 386 1
Python OS.PATH MODULE os.path.getmtime() Method 482 1
Python OS.PATH MODULE os.path.getatime() Method 313 1
Python OS.PATH MODULE os.path.splitdrive() Method 400 0
Python OS.PATH MODULE os.path.splitext() Method 393 0
Python OS.PATH MODULE os.path.split() Method 356 0
Python OS.PATH MODULE os.path.sameopenfile() Method 288 0
Python OS.PATH MODULE os.path.samefile() Method 365 0
Python OS.PATH MODULE os.path.relpath() Method 335 0
Python OS.PATH MODULE os.path.realpath() Method 491 0
Python OS.PATH MODULE os.path.join(path, *paths) Method 352 0
Python OS.PATH MODULE os.path.normpath() Method 432 0
Python OS.PATH MODULE os.path.ismount(path) Method 293 0
Python OS.PATH MODULE os.path.link() Method 325 0
Python OS.PATH MODULE os.path.isfile(path) Method 293 0
Python OS.PATH MODULE os.path.isdir() Method 515 0
Python OS.PATH MODULE os.path.dirname() Method 354 0
Python OS.PATH MODULE os.path.isabs() Method 275 0
Python OS.PATH MODULE os.path.commonprefix() Method 304 0
Python OS.PATH MODULE os.path.commonpath() Method 294 0
Python OS.PATH MODULE os.path.basename() Method 297 0
Python OS.PATH MODULE os.path.abspath() Method 488 0
Python OS MODULE os.access() Method 353 0
Python OS MODULE os.get_terminal_size() Method 410 0
Python OS MODULE os.umask() Method 402 1
Python OS MODULE os.DirEntry.stat() Method 381 1
Python OS MODULE os.DirEntry.path Attribute 416 1
Python OS MODULE os.DirEntry.name Attribute 296 1
Python OS MODULE os.DirEntry.is_symlink() Method 287 1
Python OS MODULE os.DirEntry.is_dir() Method 468 1
Python OS MODULE os.scandir() Method 443 1
Python OS MODULE os.environ 711 1
Python OS MODULE Introduction to OS Module 311 1
Python OS MODULE os.system() Method 325 1
Python OS MODULE os.getpid() 344 1
Python OS MODULE os.getlogin() 356 1
Python OS MODULE os.getgroups() Method 310 1
Python OS Module os.getgrouplist() Method 331 1
Python OS MODULE os.getuid() and os.setuid() Method 754 1
Python OS MODULE os.getgid() and os.setgid() Method 346 1
Python OS MODULE os.geteuid() and os.seteuid() Method 466 1
Python OS MODULE os.getegid() and os.setegid() Method 314 1
Python OS MODULE Difference between Real, Effective and Saved UserID 303 1
Python OS MODULE Current Working Directory 354 1
Python OS MODULE : os.getenvb() , os.get_exec_path() 471 1

Comments