Last active
March 8, 2019 18:28
-
-
Save GammaGames/8ecd3b450c7f6752221b1f35c5c502f8 to your computer and use it in GitHub Desktop.
python relative import to current file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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