Sublime Text 2 - running selected python code in the interpreter - python

While editing a python script in the Sublime Text editor, I would like to run the script line by line, or block after block in the embedded interpreter.
Is there a convenient way how to do that? Perfect way for me would be:
select a few lines of code
hit a shortcut, which will run the selected code inside the interpreter

There are two choices I think, one can be using PdbSublimeTextSupport, available here: http://pypi.python.org/pypi/PdbSublimeTextSupport
Or you can try SublimeREPL, that can run Python code: https://github.com/wuub/SublimeREPL

Related

Execute Python code in an interactive shell in VS Code

I used to use Pyzo for Python coding and decided to give VS Code a try because it is more feature-rich. I came across one huge annoyance, however. In Pyzo, I am used to code „interactively“ as Pyzo executes code in an interactive shell (https://pyzo.org/features.html).
I would like to replicate that in VS Code, but so far had no luck. With the Microsoft Python extension installed, the closest I can come is to select the whole code, right click and then click on „Run Selection/Line in Python Terminal“. For long scripts, however, this is very, very slow as it first prints each line to the terminal and then executes it line by line. Pyzo seems to operate silently.
Do you have a solution? I think, VS Code would be much faster if it did not print each line to the terminal first.
Best
I use Python Interactive window and find it very useful. It is not an immediate REPL but gives you the time to write a block of code and execute it with a key stroke.
At the bottom of the interactive pane you have a command line where you can type like a REPL. It is a temporary cell (multi line)
Use Code Runner(extension available in the marketplace of VS Code) or run a bash script in the terminal (python -u [name of the file])

Sublime 3 - How do I view stored variables in Sublime like in Matlab's "Workspace"

I'm very new to Python and have loads of experience with Matlab. As the code runs, how can I view what is stored in what variable like in Matlab's workspace and Spyder IDE?
Unfortunately, Sublime is a text editor, not an IDE. Sublime does not do any code execution, it quite literally just edits text. Viewing variable values during runtime is one of the many features found in programs like Spyder that make them IDEs, not just text editors.
If you're just using Sublime, you'll need to judiciously use print statements to help you debug.
Also, running Python in interactive mode is very helpful. python -i my_script.py will load the Python interpreter after executing your script, allowing you to access variables and interact with your live script.
Hope that helps!

Get Python Shell open

So i open Python 3.7.3 and all i get is a black window that looks like the command prompt window. Where is the shell? Where do I write my code? I saw an example with this same version of python where there were 2 white windows, one with the code and the other being the shell but i am confused how to set that up.
Is there a difference between just python 3.7.3 and IDLE? As you can see I am basically lost in this whole situation.
The window that I see looks like this: https://imgur.com/a/rMOMEh5
You have a few options, to name the basic ones:
Write your python code as a plain text file with an editor of your choice, and execute using:
python myfile.py
Write your python code in a simple IDE (e.g. sublime, atom) that has fancy features such as auto-indentation and colour coding, and execute using:
python myfile.py
Write your code in a fancy IDE that allows you to have shell and code at the same time, and execute within the IDE (e.g. PyCharm)
That's the python shell where you can issue python commands. You can call a python script as stated above and even code python directly in that window. Here is an example:
Type from secrets import token_urlsafe and hit return. Now you've imported your first python module.
Type ran_num = token_urlsafe(16) and hit return. Now we've declared a variable called ran_num and gave it the value of 16 random number, letters, and characters.
Type print(ran_num) and look at the output, which should be something like this - W2Z6O4XGebDa-eXbJY5p3Q
This is just one example. There are a lot of uses.

How to run code directly from python interpreter in Sublime Text 2?

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.

Execute a python script from sublime text 2

I have been learning python since last week weeks. I am using sublime text2 editor.
I have a simple file which prints some small text. How do I run this?
I have tried using ctrl+B but it only builds the file. How can I execute it?
You can accept user input in Sublime Text with SublimeREPL module. Install it via package control.

Categories

Resources