Skip to content

Instantly share code, notes, and snippets.

@eddieantonio
Created November 26, 2014 22:46
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 eddieantonio/20cad8038bca4b350c82 to your computer and use it in GitHub Desktop.
Save eddieantonio/20cad8038bca4b350c82 to your computer and use it in GitHub Desktop.
import os.path
def parent(n=1):
"""
Hacky way to get the nth parent of THIS file.
Suppose this file was put in `/tmp/` which is symlinked to `/private/tmp`:
>>> parent(n=1)
'/private/tmp'
>>> parent(n=2)
'/private'
"""
path = os.path.realpath(__file__)
for i in xrange(n):
path = os.path.dirname(path)
return path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment