Python 你能在我的函数调用中找到错误吗?
我的当前代码显示“未定义NameError get_视频”Python 你能在我的函数调用中找到错误吗?,python,Python,我的当前代码显示“未定义NameError get_视频” 我想我试过有自助和无自助,也许我不知道这是怎么回事。你应该这样写: que = queue.Queue() get_videos(que) def get_videos(self, theQue): links = input('Enter links comma seperated: ') list = links.split(',') for i in list:
我想我试过有自助和无自助,也许我不知道这是怎么回事。你应该这样写:
que = queue.Queue()
get_videos(que)
def get_videos(self, theQue):
links = input('Enter links comma seperated: ')
list = links.split(',')
for i in list:
theQue.put(i)
return
您在函数定义之前调用它,解释器不知道您在这里谈论或试图调用什么,因此您需要在定义之后调用它
def get_videos(self, theQue):
links = input('Enter links comma seperated: ')
list = links.split(',')
for i in list:
theQue.put(i)
return
que = queue.Queue()
get_videos(que)
另外,
self
param仅适用于类方法,您可以随意命名参数,但您只传递一个值,self
在类实例上调用此函数时会自动传递-它应该在类中定义-self仅在类中使用。由于它不在类中,self只是传递给函数的另一个变量。你肯定应该删除它。如果这个函数不在类中,它就不应该有self。即使它在类中,也应该是一个staticmethod,因为它不使用self。
que = queue.Queue()
def get_videos(theQue):
links = input('Enter links comma seperated: ')
list = links.split(',')
for i in list:
theQue.put(i)
return
get_videos(que)