[英]Python script with input not running unless I execute it on terminal
I am currently working on some Python exercises and I downloaded two text editors: Brackets and Atom . 我目前正在从事一些Python练习,并且下载了两个文本编辑器: Brackets和Atom 。 I use them because I like to be able to run the program I'm writing with a simple shortcut instead of saving it and then opening it on terminal (I'm on OS X Yosemite):
我之所以使用它们,是因为我希望能够使用一个简单的快捷方式运行我正在编写的程序,而不是保存它然后在终端上打开它(我在OS X Yosemite上):
python ex3.py
Most programs run just fine, but whenever I include a raw_input()
function inside my program and I try to run it with a shortcut from Atom or Brackets, the console output just freezes. 大多数程序运行良好,但是只要我在程序中包含
raw_input()
函数,并尝试使用Atom或Brackets中的快捷方式运行它,控制台输出就会冻结。 It doesn't show any error, and I actually can run the program on Terminal just fine. 它没有显示任何错误,实际上我可以在Terminal上运行程序。
I would like to enable this feature as it is much more convenient to run my code with a shortcut without having to save and switch programs everytime. 我想启用此功能,因为使用快捷方式运行代码更加方便,而不必每次都保存和切换程序。
Thanks for your help! 谢谢你的帮助!
With Atom, I know this is not just a python problem, I first encountered it with Ruby , it is due to the fact that Atom does not currently support STDIN . 使用Atom,我知道这不仅仅是一个python问题,我第一次在Ruby中遇到了它,这是由于Atom当前不支持STDIN 。
The only current workaround (will only work for not very interactive scripts) is data file containing intended stdin input and a testing shell script eg: 当前唯一的解决方法(仅适用于非交互式脚本)是包含预期的stdin输入和测试shell脚本的数据文件,例如:
#!/bin/bash
python3 test_script.py < data_file_with_input
With Brackets, its issue page shows a number of freezing issues both closed issues and open ones. 使用括号,其问题页面显示许多冻结问题,包括已关闭问题和未解决问题。 So I'd start there and see if you can find a solution or open an issue yourself if you fail to.
因此,我将从那里开始,看看您是否可以找到解决方案,或者如果失败则自己解决问题。
From what I can gather, Atom Script doesn't support raw_input. 据我所知,Atom Script不支持raw_input。 I can't find anything regarding Adobe Brackets, but I haven't had much success with third-party programs, so I would guess that there is a similar problem there.
我找不到关于Adobe Brackets的任何信息,但是我在第三方程序方面没有取得太大的成功,所以我想那里也存在类似的问题。 Is there any reason you're not using IDLE?
您没有使用IDLE的任何原因吗? If you're looking for a more IDE environment, I can also suggest using PyDev package in Eclipse.
如果您正在寻找更多的IDE环境,我也建议您在Eclipse中使用PyDev软件包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.