I have scripts calling other script files but I need to get the filepath of the file that is currently running within the process.
For example, let\'s say I have th
Since Python 3 is fairly mainstream, I wanted to include a pathlib
answer, as I believe that it is probably now a better tool for accessing file and path information.
from pathlib import Path
current_file: Path = Path(__file__).resolve()
If you are seeking the directory of the current file, it is as easy as adding .parent
to the Path()
statement:
current_path: Path = Path(__file__).parent.resolve()