I have the following project structure
SampleProject
com
python
example
source
utils
Co
You can use the pathlib package in Python 3.0+
This gets the path to any file contained in the SampleProject folder across different platforms.
from pathlib import Path
def get_file(path):
"""
returns the absolute path of a file
:var
str path
the file path within the working dir
:returns
PureWindowsPath or PurePosixPath object
type depends on the operating system in use
"""
def get_project_root() -> Path:
"""Returns project root folder."""
return Path(__file__).parent.parent
return get_project_root().joinpath(path)
Then simply call the function with the file_path as an argument:
filePath = get_file('com/python/example/source/utils/configManager.py')
And then the usual procedure:
while open(filePath) as f: