Python,按任意键退出 [英] Python, Press Any Key To Exit

查看:1921
本文介绍了Python,按任意键退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,正如标题所述,我想要一个正确的代码来关闭我的python脚本. 到目前为止,我已经使用input('Press Any Key To Exit')了,但是这样做会产生一个错误. 我想要一个无需关闭即可关闭脚本的代码.

So, as the title says, I want a proper code to close my python script. So far, I've used input('Press Any Key To Exit'), but what that does, is generate a error. I would like a code that just closes your script without using a error.

有人有想法吗? Google给了我输入选项,但我不想要 它因以下错误而关闭:

Does anyone have a idea? Google gives me the input option, but I don't want that It closes using this error:

Traceback (most recent call last):
  File "C:/Python27/test", line 1, in <module>
    input('Press Any Key To Exit')
  File "<string>", line 0

   ^
SyntaxError: unexpected EOF while parsing

推荐答案

您是否尝试过raw_input()?可能是您在python 2.x上使用input()时遇到了语法错误,这将尝试eval取得的结果.

Have you tried raw_input()? It could be that you are getting a syntax error by using input() on python 2.x, which will try to eval whatever it gets.

这篇关于Python,按任意键退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆