Skip to content

Instantly share code, notes, and snippets.

@izikeros
Last active March 14, 2024 09:59
Show Gist options
  • Select an option

  • Save izikeros/74737eecacd95c89c5eaf4791fb72581 to your computer and use it in GitHub Desktop.

Select an option

Save izikeros/74737eecacd95c89c5eaf4791fb72581 to your computer and use it in GitHub Desktop.
[get python project root] #python
# if this file is located in e.g.
# my_project/src/get_project_root.py
# it will return absolute path to the project root e.g.
# /home/john/projects/my_project
# If you have different structure - play with chaining '.parrent'
def get_project_root() -> Path:
return Path(os.path.dirname(os.path.realpath(__file__))).parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment