Getting user input while running a python script in atom

≡放荡痞女 提交于 2019-12-04 03:25:57
kasparg

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

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.

If you prefer to switch to Sublime (which also has a problem with user inputs), see this answer - Sublime Text 2 console 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).

Install atom-shell-commands .
Look up at the Running in a new window sample in the linked page.
Edit the config file like this :

"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 in my user folder /.atom, but you can save it elsewhere, it should not be an issue.

The 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'll find a 'run with python 3' under Packages > Atom Shell Commands.
Edit the name and the keyboard shortcut as you see fit.
Clicking on the menu, a new command prompt window is displayed : it supports also user input.
Worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!