This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Closed 2 years ago.
I use Sublime Text 2 but it won't let me enter any value when my code asks for user input. (In other words: input() in Python and gets in Ruby fail to correctly prompt me for input).
Python throws an EOFError error (what you get when user doesn't enter anything).
Simply USER INPUT isn't working in Sublime Text 2 for me.
EDIT: FOR EXAMPLE
try:
text = input('Enter something: ')
print text
except EOFError:
print('\nEOFError')
=> Enter something: #cannot enter anything to var "text"
=> EOFError
=> [Finished]
Sublime text doesn't support that. But you can get around it (at least in python) by using SublimeREPL, I use this for everything, it works pretty great. Its a little cooky though, as the tab is still editable like a normal sublime tab (which is good and bad)...
It also allows you to run the interpreter in multiple tabs, its basically awesome.
To install it you need package control this lets you easily install plugins. To get it go here, and follow the instructions. Once thats done:
in Sublime press ctrl + shift + P (linux command in ST for 'goto anything').
Type in 'install',
click on 'sublime package control: install package'.
Then select SublimeREPL. It will install it automatically.
To use it go to Tools>sublimerepl>python from the menus.
To make the default build system SublimeREPL, you can follow these instructions.
Since, Sublime not directly support for input console. So, it is easy to get input in Sublime with following extra steps:
Make sure that you have install Package control in Sublime.
If you have no install Package control then, go to here then, click install Now button (top right) copy those code and paste it in your Console (make sure you have tick the Show Console option) and Press Enter. (after that restart sublime)
Go to ->Command Palette(Cltr + Shift + p) click "Package Control: Install Package"
Search : "SublimeRepl" and wait for Installing.
Once, it is Installed, ,Restart Sublime
Go to Tools you will see ""SublimeRepl" option at the bottom (which indicates that it is successfully installed in your sublime)
To run python scripts: Go to Tools->SublimeRepl->Python->Python-RUNcurrentfile option and your code is run in new Repl Tab.
Note: This works fine for sublimeText3 (windows )
Related
I am a fresh python programmer. I started using VS Code because of its built-in terminal. (Before that I was using IDLE as an editor.)
My problem is, when I writing the code below in IDLE, all I need to do is to press enter to indent the new line to align with the previous variable.
someFunction(longVariable,
longString,
longWhatever)
In VS Code, it does this when I press enter:
someFunction(longVariable,
longString,
longWhatever)
Funny thing is when I align the "longString" by myself, It goes to the exact point where I want it to be as I press enter after comma. Like this:
someFunction(longVariable,
longString,
longWhatever)
How can I make it behave like IDLE?
I use it a lot.
In addition to installing the ms-python extension that #TheDude suggested, I had to install a formatter. The options are autopep8, YAPF, and Black. Here are the install commands (you only need one of them, I chose YAPF because I was getting weird results with autopep8):
pip install yapf
pip install autopep8
pip install black
Now, I could not get it working that it would auto-format when I return a line. There is a User Setting parameter called editor.formatOnType which I thought would take care of this, but it seems to have no effect. BUT, there is also a User Setting parameter called editor.formatOnSave that auto-formats your file every time you save it. If you change this in your user settings "editor.formatOnSave": true then every time you save your file, it gets auto-formatted.
You can also use the auto-formatting hotkeys and it will have the same effect:
Windows: Shift + Alt + F
Mac: Shift + Option + F
Ubuntu: Ctrl + Shift + I
Install the ms-python Extension.
This offers linting, intellisense, and code-formatting. I'm not sure if it's exactly like IDLE but I've been using it for Python development for several months and it does right by me.
Click this button
The enter Python in the search box and press enter
The Extension published by Microsoft is the one I recommend
This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Closed 2 years ago.
I use Sublime Text 2 but it won't let me enter any value when my code asks for user input. (In other words: input() in Python and gets in Ruby fail to correctly prompt me for input).
Python throws an EOFError error (what you get when user doesn't enter anything).
Simply USER INPUT isn't working in Sublime Text 2 for me.
EDIT: FOR EXAMPLE
try:
text = input('Enter something: ')
print text
except EOFError:
print('\nEOFError')
=> Enter something: #cannot enter anything to var "text"
=> EOFError
=> [Finished]
Sublime text doesn't support that. But you can get around it (at least in python) by using SublimeREPL, I use this for everything, it works pretty great. Its a little cooky though, as the tab is still editable like a normal sublime tab (which is good and bad)...
It also allows you to run the interpreter in multiple tabs, its basically awesome.
To install it you need package control this lets you easily install plugins. To get it go here, and follow the instructions. Once thats done:
in Sublime press ctrl + shift + P (linux command in ST for 'goto anything').
Type in 'install',
click on 'sublime package control: install package'.
Then select SublimeREPL. It will install it automatically.
To use it go to Tools>sublimerepl>python from the menus.
To make the default build system SublimeREPL, you can follow these instructions.
Since, Sublime not directly support for input console. So, it is easy to get input in Sublime with following extra steps:
Make sure that you have install Package control in Sublime.
If you have no install Package control then, go to here then, click install Now button (top right) copy those code and paste it in your Console (make sure you have tick the Show Console option) and Press Enter. (after that restart sublime)
Go to ->Command Palette(Cltr + Shift + p) click "Package Control: Install Package"
Search : "SublimeRepl" and wait for Installing.
Once, it is Installed, ,Restart Sublime
Go to Tools you will see ""SublimeRepl" option at the bottom (which indicates that it is successfully installed in your sublime)
To run python scripts: Go to Tools->SublimeRepl->Python->Python-RUNcurrentfile option and your code is run in new Repl Tab.
Note: This works fine for sublimeText3 (windows )
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?
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.
I use Sublime Text and am using the terminal to run my code.
I would prefer to use the Python Shell to run my code, as it has color and is not so hard to look at.
Is there any easy way to do this other than saving then opening in IDLE?
You can use ctrl-b to run your python in sublime. If you want to use a different interpreter you can customise under Tools -> Build System
I suggest you check out IPython. You can run it through your terminal or through an IPython Notebook in your browser.
Stick with Sublime text. It's a popular text editor with syntax highlighting for several different programming languages. Here's what you need to do:
Press Ctrl + Shift + P to bring up command palette and enter "python".
Choose the option that says something like "Set syntax to Python".
Enter Python code then Ctrl + Shift + B to build the project.
Code will run below in another view(you will probably be able to move it to the side).
This is the standard procedure for a python setup in sublime text, but you may need to install
SublimeREPL for python in order to get user input. Just give it a Google search.
This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Closed 2 years ago.
I use Sublime Text 2 but it won't let me enter any value when my code asks for user input. (In other words: input() in Python and gets in Ruby fail to correctly prompt me for input).
Python throws an EOFError error (what you get when user doesn't enter anything).
Simply USER INPUT isn't working in Sublime Text 2 for me.
EDIT: FOR EXAMPLE
try:
text = input('Enter something: ')
print text
except EOFError:
print('\nEOFError')
=> Enter something: #cannot enter anything to var "text"
=> EOFError
=> [Finished]
Sublime text doesn't support that. But you can get around it (at least in python) by using SublimeREPL, I use this for everything, it works pretty great. Its a little cooky though, as the tab is still editable like a normal sublime tab (which is good and bad)...
It also allows you to run the interpreter in multiple tabs, its basically awesome.
To install it you need package control this lets you easily install plugins. To get it go here, and follow the instructions. Once thats done:
in Sublime press ctrl + shift + P (linux command in ST for 'goto anything').
Type in 'install',
click on 'sublime package control: install package'.
Then select SublimeREPL. It will install it automatically.
To use it go to Tools>sublimerepl>python from the menus.
To make the default build system SublimeREPL, you can follow these instructions.
Since, Sublime not directly support for input console. So, it is easy to get input in Sublime with following extra steps:
Make sure that you have install Package control in Sublime.
If you have no install Package control then, go to here then, click install Now button (top right) copy those code and paste it in your Console (make sure you have tick the Show Console option) and Press Enter. (after that restart sublime)
Go to ->Command Palette(Cltr + Shift + p) click "Package Control: Install Package"
Search : "SublimeRepl" and wait for Installing.
Once, it is Installed, ,Restart Sublime
Go to Tools you will see ""SublimeRepl" option at the bottom (which indicates that it is successfully installed in your sublime)
To run python scripts: Go to Tools->SublimeRepl->Python->Python-RUNcurrentfile option and your code is run in new Repl Tab.
Note: This works fine for sublimeText3 (windows )