To get the Present working directory use the below
import os
pwd = os.getcwd()
-------------------------------------------------------------------------------------------
To get the full path to the directory a Python file is contained in, write following in the file:
import os
script_dir_path = os.path.dirname(os.path.realpath(__file__))
(Note that above won't work if you've already used os.chdir()
to change your current working directory since the value of the __file__
is relative to the current working directory and is not changed by aos.chdir()
call.)
---------------------------------------------------------------------------------------
Documentation references for the modules, constants, and functions used above:
Comments
Post a Comment