出于测试目的,我试图同时在 python 控制台中输入多个命令。
例如:
userInput = None
while userInput != 'end':
userInput = input('$ ')
userInput = userInput.strip()
if userInput == 'one':
print('all')
elif userInput == 'two':
print('at')
elif userInput == 'three':
print('once')
是否可以在不再次触摸键盘的情况下输入“一”,然后输入“二”,然后输入“三”。
类似于:
一\rtwo\rthree\r
提前感谢您的帮助!!!
最佳答案
有时我喜欢修改input
,所以我可以在空闲状态下按F5 进行测试。在您的情况下,例如,您可以在代码之前添加:
def input(prompt, inputs=iter('one two three end'.split())):
x = next(inputs)
print(prompt + x)
return x
然后你不需要输入任何内容。输出是:
$ one
all
$ two
at
$ three
once
$ end
关于python - 如何在 python 控制台中一次输入多个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39061989/