Created
April 22, 2015 14:18
-
-
Save FrankFonts/31333d393b349050f455 to your computer and use it in GitHub Desktop.
Path in Python
This file contains hidden or 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 os | |
print("Path at terminal when executing this file") | |
print(os.getcwd() + "\n") | |
print("This file path, relative to os.getcwd()") | |
print(__file__ + "\n") | |
print("This file full path (following symlinks)") | |
full_path = os.path.realpath(__file__) | |
print(full_path + "\n") | |
print("This file directory and name") | |
path, file = os.path.split(full_path) | |
print(path + ' --> ' + file + "\n") | |
print("This file directory only") | |
print(os.path.dirname(full_path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment