Skip to content

Instantly share code, notes, and snippets.

@revolutionisme
Created October 17, 2019 09:56
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 revolutionisme/0e8ec6bb7f9554d1cfa6098225a95cea to your computer and use it in GitHub Desktop.
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
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