Skip to content

Instantly share code, notes, and snippets.

@willjobs
Last active January 31, 2021 02:23
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 willjobs/89d8cd0f17163d99882e54256c890f5a to your computer and use it in GitHub Desktop.
Save willjobs/89d8cd0f17163d99882e54256c890f5a to your computer and use it in GitHub Desktop.
Python Relative Imports
# allows importing of ModuleB from ModuleA within the same subdirectory, when the code is run from a parent directory
# see https://stackoverflow.com/a/49375740/1102199
import os
import sys
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment