Created
September 28, 2012 08:38
-
-
Save non117/3798672 to your computer and use it in GitHub Desktop.
先祖path
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
# -*- coding: utf-8 -*- | |
import os | |
def get_ancestor_dir(path, n): | |
''' | |
pathからn階層上のディレクトリを返す | |
path: ディレクトリの文字列. os.path.abspath(__file__)とかを想定. | |
n: 遡る階層の数 | |
return: パスの文字列 | |
''' | |
return n == 0 and path.replace('\\', '/') or get_ancestor_dir(os.path.dirname(path), n - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment