先祖path
# -*- 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