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.
Related
I am teaching a class that uses VScode.
I am used to teaching using IDLE, and it is very nice for the students to be able to call their defined functions and run snippets of code in a python terminal, for debugging purposes.
In VScode, they I have been unable to do the same in a satisfactory way.
Option1: I can select all code, right click and run selection/line on terminal. This works for small snippets, but I cannot do it for the whole file (even after selecting the whole file with ctrl-A). On linux, this works, but on windows, it does not, unfortunately (and my students use windows)
Option2: I can use the debug console. This requires adding a breakpoint in one of the last lines of the file, and does not offer tab completion. It works, but is less convenient than IDLE.
Option 3: I can also add the commands to run to the bottom of the file (which is a least preferred alternative, given that is forgoes the interativity of the read-print-eval loop).
Is there any better solution? Installing a VScode extension would not be a problem.
Visual Code is just a text editor like your traditional notepad. to run and debug any kind program you need to install the particular extension for the programming language.
In your case you are using python so you need to install the extension of it. the best one is the "Python" which is developed by microsoft itself. go to your extensions manager and install this extension. right click and click "run python file in terminal" and you are all set.
this will run exactly as they run from the idle(which is default IDE provided by python itself) you can enter the arguments from the console itself. according to me this is the best way to run and debug python programs in VScode.
another way is that VScode shows which python version is installed on your computer on the left bottom side, click on it and the programs will use this interpreter.
out of all the ways listed here and many others, the best method is to run the program in the terminal which is the recommend by python itself and many other programmers.
this method is very simple. what you have to do is open up your command prompt and type the path where python.exe is installed and the type the path of the your program as the argument and press enter. you are done !
ex : C:\Python27\python.exe C:\Users\Username\Desktop\my_python_script.py
You can also pass your arguments of your program in the command prompt itself.
if you do not want to type all this and then just use the solution mentioned above.
hope that your query is solved.
regards
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
I'm running a python script using Sublime Text 2. To run the script, I use command B--this works great until I want to explore some variable by typing it into the python interpreter, as the interpreter does not appear to be interactive. Is there any way to be able to input code into Sublime Text 2's interpreter in order to test ideas and code snippets before I add them to the main script?
I don't think sublime support it. I know you can use SublimeREPL when you need pass some users inputs.
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 am just learning python as my first programming language, and I just installed python 3.3, 64 bit on my windows 7 OS.
I installed komodo edit 8.0, and I am trying to print ('Hello world'). I set up the correct path so that I can access python through my command prompt.
From komodo, I saved my helloworld.py file to my desktop.
When I try to run the command prompt, I search for the file, and it says file not found, or file does not exist. I can open the folder from komodo, but it appears that it is empty. When I open the folder directly from my desktop, I see the file is in there, so it seems that komodo is not recognizing it.
How can I get Komodo to recognize my saved file and run it in python? I am very new so please go step by step if you can.
Thank you!
Many of the comments you've received recommend avoiding Komodo IDE. But you're not using Komodo IDE! You are using Komodo Edit, so the comments about IDEs just don't apply.
Sure, you could use Notepad++ or even plain old Notepad, but neither of those offers any real benefit over Komodo Edit. In fact, you would be losing a valuable feature of Komodo (both IDE and Edit version): realtime syntax checking.
I use Komodo IDE and like it quite a lot. If you want to run Python programs inside Komodo and debug them right there, Komodo IDE is a great choice.
One problem may be simply that you're expecting Komodo Edit to offer the same features as Komodo IDE. It doesn't. It's just a very nice editor. You need to run your Python code outside Komodo using the command line or other means. Just open a command prompt, cd to your directory, and type python yourfilename.py.
But you say you already tried that? It must be simply a matter of being in the wrong directory.
If you have your .py file open in Komodo, do a Ctrl+O right there, and the Open File dialog will show you the file's path at the top of the dialog. You can use Alt+D to select the path, and from there you can copy it and paste it into the command line if you need to cd to that directory.
If you'd like to use an interactive debugger (an excellent idea!) without paying for Komodo IDE, you can use PythonWin.
Install Mark Hammond's Python for Windows extensions. Included in this package is PythonWin. You can open your .py file in PythonWin and select File/Debug/Step In to start debugging your code. Then you can use the other commands on the File/Debug menu to step through it. Take note of the F10/F11/etc. keyboard shortcuts which give quicker access to these commands.
Whichever way you do it, I highly recommend using an interactive debugger like this when learning a new language. Being able to stop the code and look at your variables right then and there is a huge improvement over being limited to print statements for debugging.
So I disagree quite strongly with the recommendations against using an IDE like Komodo. The very first thing I look for when I learn a new programming language is an interactive visual debugger. I don't care too much whether that debugger comes packaged as part of an "IDE" or is a standalone debugger, as long as it shows the source code, makes it easy to single step, and shows the variables whenever it's paused.
Ok heres what I personally do.
Open run, type in cmd
Navigate to whatever directory my mypythonfile.py file is
Open whatever text editor you feel like ( personally i use notepad++ because it is NOT an IDE like kodomo, but just a pretty text editor.)
Type python mypythonfile.py and hit enter. This will run the program.
Open mypythonfile.py in text editor program.
Make changes to the python file.
Go back to the cmd window and press arrow up ( to go to the last typed command) and then press enter again, to run the program again.
Repeat steps 6-7 until your program is perfect.
It seems like you are having trouble with the Kodomo IDE instead of the actual learning python process. IDEs are complicated tools with lots of buttons that are scary. Learn the language first, then once you are comfortable there, then maybe you will use an IDE? Or maybe you will just keep using a text editor instead. Thats up to you.