我有一个提示用户键盘输入的 python 程序。根据输入,完成某段代码。
List of items in this dfsu file:
1. Significant Wave Height
2. Peak Wave Height
3. Wave Direction
Chose item from the list above
我想一直选择1,因为这个问题重复了5000次,所以我不想手动输入1。我无权访问源代码来硬编码这个,但我想知道是否有每次询问此问题时强制用户输入为 1 的方法?
谢谢, 金佰利
最佳答案
Is there a way to force the user input to be 1 each time this question is asked?
yes
, 有。
运行 yes
并将其输出通过管道传递给您运行的命令:
yes 1 | the_command_you_originally_ran
默认情况下,yes
重复输出 y
,假设您想自动确认类似“are-you-sure”的提示,但您可以运行 yes 1
使其在无限循环中输出 1
。
关于Linux屏幕输入自动响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23395553/