Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15910

how to declare value as none the redeclare it then use it for an if statement in python? [closed]

$
0
0

My question is pretty simple how do how to declare value as none the redeclare it then use it for an if statement in python?

global commandcommand = Nonedef user_commands():    def take_command():    try:        with sr.Microphone() as source:            print('listening...')            voice = listener.listen(source)            command = listener.recognize_google(voice)            command = command.lower()            if 'alexa' in command:                command = command.replace('alexa', '')                print(command)    except:        pass    return commanddef run_alexa():    global command    command = user_commands()    ...    if 'Play' in command:        ...

what is happening when I do this is:TypeError: argument of type 'NoneType' is not iterable

What I am doing is creating an alexa which ask to take commands then do the command. the variable for the command is set equal to the person says but in python it doesnt like to have a variable without a type so I said no then said ill redeclare it but it does not work,


Viewing all articles
Browse latest Browse all 15910


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>