UnboundLocalError Traceback (most recent call last) Cell In[6], line 492 488…
- User
UnboundLocalError Traceback (most recent call last) Cell In[6], line 492 488 dt.to_excel(save_file, index = False) 490 print(datetime.datetime.today() - st) --> 492 main()
Cell In[6], line 457, in main() 456 def main(): --> 457 dt, col_table = load_data(way_to_file) 459 # Укажите по каким колонкам идет выбор данных возможин по ИНН или по ФИО менджера 460 # в базе данных указывать такие колонки col_db = 'INN', col_db = 'SUP_EMPLOYEE_NAME' 462 table = load_from_db(df = dt, col_table = col_table, col_db = col_db)
Cell In[6], line 39, in load_data(way) 37 col_tab = col 38 break ---> 39 return table, col_tab
UnboundLocalError: cannot access local variable 'col_tab' where it is not associated with a value
- Assistant
The
UnboundLocalErroryou're encountering indicates that you're trying to return the variable from the function, but it may not have been initialized before the return statement is reached. This typically occurs when execution of the code does not enter the conditional block that initializes . - User
check the function: def load_data(way): table = pd.read_excel(way) col_tab = None for col in list(table.columns.values): print(col) if re.match(r'(?i)ИНН.* | INN.*', str(col)): col_tab = col break if col_tab is None: raise ValueError("Колонка с ИНН не найдена, проверь файл!") return table, col_tab
- Assistant