
Python3 /Users/mbp/Documents/my-project/python-snippets/notebook/data/src/file_path.py dst/target_2.txt # read target file: # !! This is "target_2.txt" !! # getcwd: /Users/mbp/Documents/my-project/python-snippets/notebook # _file_: data/src/file_path.py # basename: file_path.py # dirname: data/src # abspath: /Users/mbp/Documents/my-project/python-snippets/notebook/data/src/file_path.py # abs dirname: /Users/mbp/Documents/my-project/python-snippets/notebook/data/src # target_path_1: data/src/target_1.txt # read target file: # !! This is "target_1.txt" !! # target_path_2: data/src/./dst/target_2.txt # normalize : data/dst/target_2.txt # read target file: # !! This is "target_2.txt" !! # getcwd: /Users/mbp/Documents/my-project/python-snippets/notebook/data/src # target_path_1: target_1.txt # read target file: # !! This is "target_1.txt" !! # target_path_2. Pwd # /Users/mbp/Documents/my-project/python-snippets/notebook It is possible to change the current directory using os.chdir() in the code. Regardless of the directory where Jupyter Notebook is started, the current directory is where. Note that _file_ cannot be used in Jupyter Notebook (.
#Get file path linux how to#
See the following article on how to get and change the current working directory.

_file_ is useful for reading other files based on the location of the current file. In Python, you can get the path (location) of the current file, i.e., currently running script file (.
