Python 为什么它说它缺少位置参数?
好的,我得到了如下代码:Python 为什么它说它缺少位置参数?,python,discord.py,Python,Discord.py,好的,我得到了如下代码: groups = ['Z208', 'D204'] def show_next_lesson(self, group): workbook = load_workbook(filename=f'/home/xyz/Desktop/{group}.xls') sheet = workbook.active print(sheet) class Wwsi(commands.Cog): def __init__(self, bot):
groups = ['Z208', 'D204']
def show_next_lesson(self, group):
workbook = load_workbook(filename=f'/home/xyz/Desktop/{group}.xls')
sheet = workbook.active
print(sheet)
class Wwsi(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def nl(self, ctx):
for role in ctx.author.roles:
x = str(role)
if x in groups:
sheet = x
show_next_lesson(sheet)
它在函数调用时返回错误缺少位置参数“group”
所以基本上
sheet
变量是空的?但是,如果我打印(工作表),它实际上会返回组数。我真的不明白它是如何工作的,如果有任何建议,我将不胜感激;) 如果您将show\u next\u lesson()
移动到您的课堂中,它将起作用:
class Wwsi(commands.Cog):
def __init__(self, bot):
self.bot = bot
def show_next_lesson(self, group):
workbook = load_workbook(filename=f'/home/xyz/Desktop/{group}.xls')
sheet = workbook.active
print(sheet)
@commands.command()
async def nl(self, ctx):
for role in ctx.author.roles:
x = str(role)
if x in groups:
sheet = x
self.show_next_lesson(sheet)
show\u next\u第
课不在课堂上,所以self
是一个普通的名字哦,我明白了:D谢谢,我现在明白了:Dself
关键字是关键。非常感谢。@Rizonnself
不是关键字。它只是约定用于引用调用该方法的对象实例的名称。因此,您应该期望任何以self
作为第一个参数的函数定义都是类的方法。