Jan-14-2021, 03:26 PM
Hello,
I try to write some Excel functions with xlwings and openpyxl.
For example one function will get details about an item from another Excel file.
Everytime a function is run, it has to open that other Excel file, do its thing and close the file again.
Since I will have many functions that work with other Excel files, I thought I'll do that with an decorator.
I don't have to code right here but it looks something like this:
I tried to move the
Since it is not a single variable but several ones, I guess I don't want to make them global.
I try to write some Excel functions with xlwings and openpyxl.
For example one function will get details about an item from another Excel file.
Everytime a function is run, it has to open that other Excel file, do its thing and close the file again.
Since I will have many functions that work with other Excel files, I thought I'll do that with an decorator.
I don't have to code right here but it looks something like this:
def excel_wrapper(func): def inner(*args, **kwargs): open_excel_file('filename') dict1 = {...} returnvalue = func(*args, **kwargs) close_excel_file() return returnvalue return inner @excel_wrapper def get_value(item, value): for x in dict1 ... get_value('banana', 'color')This results in a NameError because dict1 is not defined.
I tried to move the
open_excel_file
etc. stuff from the inner function to the decorator function but this gave me the same error.Since it is not a single variable but several ones, I guess I don't want to make them global.