Mar-30-2024, 02:46 AM
The following will get the absolute paths.
Note that root_dir will get path to the file, including the python file name.
If you just wanted the current path, use
You would also have to assure that the current path is the the same as __file__ path.
You can still use __file__. but to get previous directory,would need
Note that root_dir will get path to the file, including the python file name.
If you just wanted the current path, use
root_dir = Path('.')
You would also have to assure that the current path is the the same as __file__ path.
You can still use __file__. but to get previous directory,would need
parent_dir = root_dir.parent.parent.absolute()
root_dir = Path(__file__).absolute() print(root_dir) parent_dir = root_dir.parent.absolute() print(parent_dir)