【发布时间】:2013-03-28 06:23:30
【问题描述】:
我正在解决这个问题的答案:Python Interactive Shell Type Application
我的代码是这样的
def main():
while True:
s = input('> ')
if s == 'hello':
print('hi')
if s == 'exit':
break
if __name__ == "__main__":
main()
如果我运行它并输入 hello,我会得到
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined
我应该如何监听文本,并根据结果调用不同的函数?
【问题讨论】:
标签: python shell undefined interactive