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

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

问题描述

不确定是我找对地方了还是这个功能还没有实现,但是在安装 atom 脚本包并在需要用户输入的程序上对其进行测试后,我意识到我无法像从 shell 运行程序时那样为 input() 输入任何内容.我偶然发现了这个帖子,这让我怀疑该功能尚未补充说,但我只是想确定.这难道不是一件非常基本的事情吗?还是我必须坚持将 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 - 如何在 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(用户输入也有问题),请参阅此答案 - Sublime Text 2 控制台输入.

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天全站免登陆