在Atom中运行python脚本时获取用户输入 [英] Getting user input while running a python script in atom

查看:142
本文介绍了在Atom中运行python脚本时获取用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定我是否只是在寻找合适的位置还是尚未实现此功能,但是在安装了原子脚本包并在需要用户输入的程序上对其进行了测试之后,我意识到我无法通过input()键入任何内容,这是我从shell运行程序时无法执行的操作.我偶然发现了此线程,这使我怀疑该功能尚未实现添加,但我只是想确定一下.这不是一件很基本的事情吗?还是我必须坚持仅将atom用作文本编辑器并从CLI运行文件?

Not really sure whether I'm just not looking in the right place or whether this feature is yet to be implemented, but after installing the atom script package and testing it out on a program that requires user input, I realize that I can't type in anything for input() the way I can when running the program from the shell. I stumbled upon this thread which makes me suspect that the feature hasn't been added, but I just wanted to be sure. Isn't this a pretty basic thing to be able to do? Or do I have to stick to using atom purely as a text editor and running the file from the CLI?

推荐答案

某些文本编辑器(包括Atom和Sublime)不喜欢用户输入(raw_input()).是的,您必须从CLI运行该文件.

Some text-editors (including Atom and Sublime) don't like user input (raw_input()). Yes, you'd have to run the file from CLI.

但是,您可以通过使用其他文本编辑器(如Notepad ++)来解决此问题(请参阅此答案以在notepad ++中运行Python-

You could, however, get around this problem by using other text editors like Notepad++ (see this answer to run Python in notepad++ - How to Execute a Python File in Notepad ++?), where user input works fine.

如果您希望切换到Sublime(用户输入也有问题),请参见以下答案-

If you prefer to switch to Sublime (which also has a problem with user inputs), see this answer - Sublime Text 2 console input.

如果您想坚持使用Atom,当然,另一种方法是在调试/开发时在raw_input中对要查找的变量进行硬编码(但不要忘记在调试后切换回raw_input ).

If you'd want to stick with Atom, an alternative, of course, would be to hard-code the variables you are looking for in raw_input while debugging/developing (but don't forget to switch back to raw_input after debugging).

这篇关于在Atom中运行python脚本时获取用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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