input vs. raw_input: Python Interactive Shell Application? -
i working off of answer in question: python interactive shell type application
my code looks this
def main(): while true: s = input('> ') if s == 'hello': print('hi') if s == 'exit': break if __name__ == "__main__": main() if run it, , type hello, get
file "<string>", line 1, in <module> nameerror: name 'hello' not defined how should listening text, , calling different functions based on result?
you're running under python 2.x, input() evaluates type python expression. thus, it's looking variable named hello, and, since haven't defined one, throws error. either use python 3.x, or use raw_input().
from parentheses in print assume intended run under python 3.x.
Comments
Post a Comment