how can i vscode run python without terminal command - python

Is there a way to run Python in Vscode terminal without command?
current result
want result
I've also tried changing the run console from terminal to debug console in Launch.json, but it's not a good way because it's not set globally and don't get key input.
Is there a good way?
And apart from this question, is there any way to get the finished time print like when running Python on a sublime?
I think it's too inefficient to take a final time for each python code.

Right click "Run main.py"

Related

I think ive setup vscode the wrong way or not able to find out a few root reasons for a few errors

why is this error there in the terminal?
i was trying to run a simple file after saving it yet it wasnt able to locate the file in the directory as mentioned, hence was giving the following error.
The simplest way to fix this is to remove : at the end of second line. It is a typo which kind of destroys rest of the code.
Delete your current terminal, or Ctrl+Z and press Enter to exit the current python interactive mode.
When your terminal looks like this you can use the play button to run the code.
When your terminal looks like this, it means that you have opened the python interactive terminal, where you can directly type the code and run it, but you cannot run the command.
By the way, as others have said there is a bug in your code, you need to remove the semicolon at the end of the second line.

Python breakpoint() without console

I often use the python breakpoint() command as a way of debugging code or for changing the values of variable on-the-fly. This works great when I launch a python script from the (windows) console, as breakpoint() lets me type commands in that console.
My question is how do I do achieve something similar when running a python script launched some other way? For example, when I package my code into an .exe with PyInstaller (with the no-console option to keep it tidy) and launch the .exe, breakpoint() does nothing at all. I know one way to remove this problem is to compile the .exe without the no-console option, but I'd rather have it there as it just keeps everything clean. A similar problem also arises when running a python script via a os.execl() call in another.
Is there someway of making the code launch its own console whenever breakpoint() is called, and having that console control the debugging commands? I suspect that this is possible through manipulating the PYTHONBREAKPOINT variable, but I don't know how, or where to start looking.

How to use VS Code - Python Shell

So I am relatively new to programming and used to use Python's own "IDLE". After I run a ".py" file with IDLE, I am used to getting a python shell or a command window, I don't really know the terminological name for it, where I could play around with the objects inside the script.
For example, if I had a list A=[1,2,3] inside the program, after I run it I get a command console that says ">>" and I can say ">>A" which gives me "[1,2,3]" and I can add elements to A etc.
Now, I want to start using VS Code but I can't seem to find that particular thing. I have a terminal where I can run python code if I give the command "python" first, but It doesn't seem to effect anything inside the script.
I want to use that to see if some objects are working fine and to check their types etc. I add more lines to code after I try from there first, if that makes sense.
Sorry for really bad terminology, I really don't know the names but I can try even more if it's not clear.
Thanks a lot in advance.
Are you looking for the Integrated Terminal of VS Code?
Here are some ways to open the terminal:
Use the ⌃` keyboard shortcut with the backtick character.
Use the View > Terminal menu command.
From the Command Palette (⇧⌘P), use the View: Toggle Integrated Terminal command.
In the window that shows up, enter python and you'll get the Python shell you're looking for.
Try using the integrated terminal inside vs code and make sure that python and pip are properly configured. Type python in the command line and make sure the terminal points to the same folder where your program file is located.

Find the exact .py window/script that corresponds to the IPython console in Spyder

I would like to know if there is way to figure out (from the IPython console) the .py script that was used to run/execute the python commands interactively and thus got printed into the Ipython console.
For eg.
From the below screenshot, looking at the 3+3 in the Ipython console, I can see that it came in when command from untitled2.py was executed.
However when the scripts get long, and IPython output gets long and you are often shifting scripts on the left side, it can be hard to keep track.
So i was wondering if there is a way i can quickly execute some command or view some setting on Ipython console that can tell me that the above line came from untitled.py.
(Spyder maintainer here) There's no way to know from which Editor you're executing some portion of code, sorry.
However, you could use dedicated consoles (under Preferences > Run > Execute in a dedicated console) to have one console per file you execute, as long as you use F5 to run each one of them.
You could edit each .py script, so the first thing it does is to print its name and functionality.
untitled2.py:
print('untitled2.py')
...

Visual studio code interactive python console

I'm using visual studio code with DonJayamanne python extension. It's working fine but I want to have an interactive session just like the one in Matlab, where after code execution every definition and computational result remains and accessible in the console.
For example after running this code:
a = 1
the python session is terminated and I cannot type in the console something like:
b = a + 1
print(b)
I'm aware that the python session can stay alive with a "-i" flag. But this simply doesn't work.
Also every time I run a code file, a new python process is spawned. Is there a way to run consecutive runs in just one console? Again like Matlab?
This sounds really essential and trivial to me. Am I missing something big here that I can't find a solution for this?
I'm the author of the extension.
There are two options:
Use the integrated terminal window (I guess you already knew this)
Launch the terminal window and type in python.
Every statement executed in the REPL is within the same session.
Next version will add support for Jupyter.
Please have a look here for some samples of what is yet to come:
#303
Screen samples and more
I added the following lines into user setting file, then it works.
Select some lines of python code, then right-click and select Run selected code in python terminal
Solution 1: Will start iPython terminal
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/K ipython"],
Solution 2: Will start a terminal like "python -i"
"python.terminal.launchArgs": ["-i"],
The following line will solve your problem.
"python.terminal.launchArgs": ["-c","\"from IPython import embed; embed()\""]

Categories

Resources