首页 > 解决方案 > 在 Spyder IDE 中使用 Python 装饰器

问题描述

我正在尝试在我的 python 代码中编写一个装饰器。当我在 Jupyter notebook 中编译它时,它运行良好,但是当我在 Spyder IDE 中运行代码时,我得到一个错误。

def search_func(sheetname):
    def insider(f):
        file = openpyxl.load_workbook("Excelfile.xlsx")
        current_sheet = file[sheetname]
        f(current_sheet)
    return insider

@search_func('Passwords')
def Longin(current_sheet):
    Name = User_name.get() + str(Password.get())
    for i in range(1,current_sheet.max_row +1):
       for j in range(1,current_sheet.max_column+1):
           if current_sheet.cell(i,j).value == Name:
               print("Hello")

我得到的错误是“Longin() 缺少 1 个必需的位置参数:'current_sheet'”

任何人都可以帮助我吗?

珍惜你的时间。

干杯

标签: python-3.xdecoratorspyder

解决方案



推荐阅读