os
module, you can get and change the current working directory where Python is running.os
module is included in the standard library, so no additional installation is required.os.getcwd()
os.chdir()
.py
) being executed can be obtained with __file__
. See the following post.__file__
os.getcwd()
returns the absolute path of the working directory where Python is currently running as a string str
.print()
.getcwd
stands for 'get current working directory'.os.path
to manipulate the path string. See the following post for details.os.chdir()
os.chdir()
.'../'
to move up.cd
command.chdir
stands for 'change directory'. Same as cd
.__file__
and os.path
functions, you can change the current directory to the directory where the running script file (.py
) exists.__file__