如何通过控制D退出Python计划?
我有一个Python程序,该程序使用一个WALE循环检查用户输入。我希望在用户输入输入时继续运行,但是当用户输入CTRL d时退出。目前,我在键入ctrl d时会得到eoferror。我是Python的新手,因此有关如何解决此问题的任何建议真的很有帮助。
这是我的代码的一个非常简单的示例:
while True:
userInput = input()
...
exit()
I have a python program that uses a while loop to check for a user input. I want it to keep running while a user enters an input, but quit when the user enters ctrl d. Currently, I get EOFError when typing ctrl d. I am new to python so any advice on how to fix this would be really helpful.
Here is a very simple example of my code:
while True:
userInput = input()
...
exit()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我用
I fixed it with
出口()关键字也很有用。它还提高了可读性。
The exit() keyword is also useful. It also improves readability.