python——我遇到了 UnboundLocalError 的问题:在分配之前引用了局部变量“命令”[重复]
发布时间:2022-05-10 13:35:43 262
相关标签:
关于我的问题,我见过类似的问题,但它们似乎没有帮助。
我的密码是
def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'give' in command:
print('give mentioned')
comand = command.replace('give' '')
print(comand)
except:
pass
return command
def run_give():
command = take_command()
print(command)
错误是
Traceback (most recent call last):
File "c:\Users\REDACTED\REDACTED\REDACTED\REDACTED\main.py", line 72, in
run_give()
File "c:\Users\REDACTED\REDACTED\REDACTED\REDACTED\main.py", line 38, in run_give
command = take_command()
File "c:\Users\REDACTED\REDACTED\REDACTED\REDACTED\main.py", line 34, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment
我尝试了很多方法来修复它,但都没有效果。
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报