Created
October 17, 2019 09:56
-
-
Save revolutionisme/0e8ec6bb7f9554d1cfa6098225a95cea to your computer and use it in GitHub Desktop.
Get the absolute path for the given relative path, the relative path is calculated from the module where this function is called
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
from os import path | |
from inspect import getframeinfo, stack | |
def get_abs_path(relative_path): | |
""" | |
Returns the absolute path for the given relative path, the relative path is calculated from where this function is | |
called | |
:param relative_path: Relative path from file_name location | |
:return: absolute path of the relative path | |
""" | |
caller = getframeinfo(stack()[1][0]) | |
return path.join(path.dirname(path.abspath(caller.filename)), relative_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment