Getting user input when running python script in atom

Not sure if I’m just not looking in the right place or this function is not yet implemented, but after installing the atom script package and testing it on a program that requires user input, I understand that I can not enter anything for input() , as I can when I run the program from the shell. I came across this topic , which is why I suspect that the function has not been added, but I just wanted to be sure. Isn't that a very simple thing? Or should I stick with using the atom solely as a text editor and run the file from the CLI?

+6
source share
2 answers

Some text editors (including Atom and Sublime) do not like user input ( raw_input() ). Yes, you will need to run the file from the CLI.

However, you can work around this problem by using other text editors such as Notepad ++ (see this answer for running Python in Notepad ++ - How to execute a Python file in Notepad ++? ), Where user input works fine.

If you prefer to switch to Sublime (which also has problems with user inputs), see this answer - the Sublime Text 2 console tab .

If you want to stick with Atom, an alternative, of course, would be to hardcode the variables you look for in raw_input when debugging / developing (but don't forget to return to raw_input after debugging).

+1
source

Install atom-shell-commands .
Look at the "Launch in a new window" page on the linked page.
Modify the configuration file as follows:

 "atom-shell-commands": commands: [ { name: "run with python 3" command: "cmd" arguments: [ "/C" "start" "$your_folder$/launch_python3.cmd" "{FileName}" ] options: cwd: "{FileDir}" keymap: 'ctrl-3' } ] 

Note. I saved the launch_python3.cmd file in my /.atom user folder, but you can save it in another place, this should not be a problem.

Cmd file contents:

 @echo off REM used by atom-shell-commands to launch python 3 in a new window $your_python_path$\python.exe %1 pause exit 

Now you can find "run with python 3" under "Packages"> "Atom Shell Commands".
Change the name and key combination as you like.
By clicking on the menu, a new command window appears: it also supports user input.
Worked for me.

0
source

Source: https://habr.com/ru/post/983815/


All Articles