import os

def output(current_file_path, *label):
    '''
    Usage: output_file_path(__file__, *label)

    Send the output file generated by a module into ./output/module/label[0]/label[1]...

    Notice: Do not iterate this function. One call per use.
    '''
    destination_directories = os.path.dirname(current_file_path).split(os.sep)
    for i in range(len(destination_directories)-1, -1, -1):
        if destination_directories[i] == 'raser':
            destination_directories[i] = 'output'
            break
    output_file_path = os.path.abspath(os.path.join(os.sep, *destination_directories, *label))
    create_path(output_file_path)
    # 星号将列表转化为递归，头一个os.sep使其输出绝对路径；外圈abspath考虑潜在的windows用户
    return output_file_path

def create_path(path):
    """ If the path does not exit, create the path"""
    if not os.access(path, os.F_OK):
        os.makedirs(path, exist_ok=True) 