def fetch_parent_dir(filepath, n=1):
    '''Returns a parent directory, n places above the input filepath.

    Equivalent to something like: '/home/user/dir'.split('/')[-2] if n=2.
    '''
    filepath = os.path.realpath(filepath)
    for i in range(n):
        filepath = os.path.dirname(filepath)
    return os.path.basename(filepath)
def fetch_parent_dir ( filepath , n = 1 ) : filepath = os . path . realpath ( filepath ) for i in range ( n ) : filepath = os . path . dirname ( filepath ) return os . path . basename ( filepath )
Returns a parent directory, n places above the input filepath.

    Equivalent to something like: '/home/user/dir'.split('/')[-2] if n=2.