我想使用 while 循环和 raw_input 编写一个接口。
我的代码如下所示:
while True:
n = raw_input("'p' = pause, 'u' = unpause, 'p' = play 's' = stop, 'q' = quit)
if n.strip() == 'p':
mp3.pause()
if n.strip() == 'u':
mp3.unpause()
if n.strip() == 'p':
mp3.play()
if n.strip() == 's':
mp3.stop()
if n.strip() == 'q':
break
但是,如果我输入 raw_input 中未指定的任何内容,我希望它中断。
if not raw_input:
break
返回和 IndentationError: unindent 不匹配任何外部缩进级别。
if not raw_input:
break
不返回任何错误,但不能按我的意愿工作。据我所知,它根本没有任何作用。
另外,如果有一种更简洁的方式来编写我的循环,我很乐意听到它。