def rec_apply(func, n):
    """
    Used to determine parent directory n levels up
    by repeatedly applying os.path.dirname
    """
    if n > 1:
        rec_func = rec_apply(func, n - 1)
        return lambda x: func(rec_func(x))
    return func
def rec_apply ( func , n ) : if n > 1 : rec_func = rec_apply ( func , n - 1 ) return lambda x : func ( rec_func ( x ) ) return func
Used to determine parent directory n levels up
    by repeatedly applying os.path.dirname