

See the following article on how to get and change the current working directory. Read the same file regardless of the current working directory.Change the current directory to the directory of the current script file.Read other files based on the location of the current script file.Get the absolute path of the current script file.Get the file and directory name of the current script file.This article describes the following contents. In Python 3.9 and later, _file_ always returns an absolute path, regardless of whether the path specified with the python command is relative or absolute. If you specify an absolute path, an absolute path is returned. If you specify a relative path, a relative path is returned. In Python 3.8 and earlier, _file_ returns the path specified when executing the python (or python3) command. _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 (.
