Skip to content

Instantly share code, notes, and snippets.

@berkorbay
Created October 17, 2022 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berkorbay/d45068d631cd7d8e22735ac99ebbc993 to your computer and use it in GitHub Desktop.
Save berkorbay/d45068d631cd7d8e22735ac99ebbc993 to your computer and use it in GitHub Desktop.
Getting to upper directories in Python
### This gist gives you the code snippet to reach upper directories
### so you can reach other functions in the document
### e.g. from mainfolder.subfolder.subfolder.examplefile import example_function
#### Include upper dirs start
dpath = os.path.dirname(os.path.abspath(__file__))
for i in range(4):
dpath = os.path.dirname(dpath)
sys.path.insert(1, dpath)
#### Include upper dirs end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment