Created
November 26, 2014 22:46
-
-
Save eddieantonio/20cad8038bca4b350c82 to your computer and use it in GitHub Desktop.
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
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