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

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.

Related

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 can I configure PyCharm so that running a Python script file is visible for Python Console

I am writing Python scripts in Pycharm with IPython installed. So I can use Python Console in Pycharm to type Python commands and check the immediate output of the codes. However, when I run a script file after pressing 'Run' button (Shift+F10), all the variables and functions are not visible to the Python Console. This is, however, the feature of Spyder, another popular Python IDE. So here is my question: how can I configure Pycharm so that running a Python script file is visible for Python Console? Thanks
You could also run the part of your code you want to test/check in the console by selecting it and then right clicking and clicking on "Execute Selection in Console Alt-Shift-E". That's what I use sometimes when the debugger is not helpful. After running the code (you can also just "run" functions or classes) the console knows the functions and you can use the same features that Spyder has. However, be aware that when you change the code you need to run it in the console once to update the console definitions!
You can not. But you can use pdb (which will break code execution where you need it and you will be able to do the same things, as in the Python Console).
And, which is better and more powerful, you can use PyCharm's debugger. It represents all available variables in tree-like structures and is really handy.

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.

Sublime Text 2 - running selected python code in the interpreter

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

Categories

Resources