【问题标题】:Python getting local-variable-data-referenced-before-assignment errorPython得到局部变量数据引用前赋值错误
【发布时间】:2022-09-28 18:22:08
【问题描述】:

我正在尝试以下代码,其中我也想使用在 try catch 之外声明的变量。但是我得到了在赋值错误之前引用的局部变量 \'data_summary\'。

以下是我的代码。

data_summary, spdj_count, mstar_count, fs_count, dataframe_ricToMsarId, ricMissingPerformanceIds, dataframe_total_cases_count, dataframe_soi1_case_count, dataframe_soi_2_case_count, dataframe_soi_3_case_count, totalperfIdBoB, dataframe_treasury_check, treasuryEmailSummary, dataframe_fs_mapping_error, fsMissingPerformanceIds, dataframe_total_cases_count, dataframe_soi1_case_count, dataframe_soi_2_case_count, dataframe_soi_3_case_count, totalBoBperfIds

    try:
        data_summary, spdj_count, msar_count, fs_count = app.compare_floats(env, running_locally, region)
    except Exception as exp:
        print(\"Error while executing Report-- execute_compare_price - CE_API_Weekly -- Message -- \" + str(exp))
    try:
        dataframe_ricToMstarId, ricMissingPerformanceIds, dataframe_total_cases_count, dataframe_soi1_case_count, dataframe_soi_2_case_count, dataframe_soi_3_case_count, totalperfIdBoB = app.getMissingRICPerformanceIDsReportDetails(
            env, running_locally, region)
    except Exception as exp:
        print(\"Error while executing Report-- execute_compare_price - CE_API_Weekly -- Message -- \" + str(exp))
    try:
        dataframe_treasury_check, treasuryEmailSummary = app.getTreasuryDetails(env,
                                                                                running_locally,
                                                                                region)
    except Exception as exp:
        print(\"Error while executing Report-- execute_compare_price - CE_API_Weekly -- Message -- \" + str(exp))
    try:
        dataframe_fs_mapping_error, fsMissingPerformanceIds, dataframe_total_cases_count, dataframe_soi1_case_count, dataframe_soi_2_case_count, dataframe_soi_3_case_count, totalBoBperfIds = app.getFactsetMappingErrorReportDetails(
            env, running_locally, region)
    except Exception as exp:
        print(\"Error while executing Report-- execute_compare_price - CE_API_Weekly -- Message -- \" + str(exp))
        if dataframe_treasury_check > 0 or (ricMissingPerformanceIds > 0 and dataframe_ricToMstarId) > 0 or (
                fsMissingPerformanceIds > 0 and dataframe_fs_mapping_error) or (
                spdj_count > 0 or mstar_count > 0 or fs_count > 0) > 0:

            ricToMstarMappingEmailSummary = reporting.printRICMissingPerformanceIDReportEmailSummary(
                dataframe_total_cases_count,
                dataframe_soi1_case_count,
                dataframe_soi_2_case_count,
                dataframe_soi_3_case_count,

有人可以帮忙吗?

  • 您的代码无效,甚至不会通过解释器的语法检查,因此无法从该代码中获取运行时错误。请先提供有效代码。

标签: python


【解决方案1】:

在第一行中,您告诉解释器使用上面任何地方都没有定义的变量。

删除第一行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    相关资源
    最近更新 更多