Created
October 7, 2014 22:23
-
-
Save GMadorell/e6dc4d13c3712edc6b01 to your computer and use it in GitHub Desktop.
Pathing. Easy way to evade the pathing problems when running an script 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 | |
TOP_LEVEL_NAME = "lorayne_numbers" | |
def __get_current_path(): | |
return os.path.dirname(os.path.abspath(__file__)) | |
def get_top_level_path(): | |
path = __get_current_path() | |
head, tail = os.path.split(path) | |
while tail != TOP_LEVEL_NAME: | |
head, tail = os.path.split(path) | |
return os.path.join(head, tail) | |
def get_path_relative_to_top_level(*args): | |
""""" | |
:param args: Pass directories followed by an optional file at the end. | |
""" | |
path = get_top_level_path() | |
for next_step in args: | |
path = os.path.join(path, next_step) | |
return path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment