如何将参数传递到

2024-04-20 14:07:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个功能:

def UPLOAD(FILE_NAME):


    try:

        client = bigquery.Client()

        dataset_ref = client.dataset(DATASET)
        table_ref = dataset_ref.table(TABLE)
        job_config = bigquery.LoadJobConfig()
        job_config.source_format = bigquery.SourceFormat.NEWLINE_DELIMITED_JSON
        job_config.autodetect = False

        with open(FILE_NAME, 'rb') as source_file:
            job = client.load_table_from_file(
                source_file,
                table_ref,
                location='EU',  # Must match the destination dataset location.
                job_config=job_config)  # API request

        job.result()  # Waits for table load to complete.

    except:
        error(job,'BLABLA')

这个函数中的一个问题是,当我试图将job参数从except传递到error函数时,它没有接收到它。你知道吗

什么是真正的错误,我不确定。。。你知道吗

错误:错误:赋值前引用了局部变量“job”

更新:

def error(job,extra):
    if extra == 'BLABLA':
        ERROR = job.error
    elif extra == 'LALA':
        ERROR = job.error
    else:
        print('else')

Tags: nameclientrefconfigsourcedef错误table