Skip to content

Instantly share code, notes, and snippets.

@GammaGames
Last active March 8, 2019 18:28
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 GammaGames/8ecd3b450c7f6752221b1f35c5c502f8 to your computer and use it in GitHub Desktop.
Save GammaGames/8ecd3b450c7f6752221b1f35c5c502f8 to your computer and use it in GitHub Desktop.
python relative import to current file
import sys
import os
# Get the absolute path from the current file
# Get the file's directory
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# If you don't have access to the __file__ global
sys.path.append(os.path.dirname(os.path.abspath(sys.argv[0])))
# Print the last item in the path
print(sys.path[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment