0

I'm trying to run a python shell file, like the one in IDLE, directly inside vscode so that I can run single lines/blocks of code interactively. Is this possible, and if so, how?

lucafossen
  • 9
  • 1
  • 3
  • It's not clear what you mean by "*run ... interactively*", but this might help: [How do I open the interactive shell/REPL in Visual Studio Code?](https://stackoverflow.com/q/61808776/2745495) – Gino Mempin Oct 04 '21 at 12:14

3 Answers3

0

Open the terminal run new terminal, and if python is added to your path, write python in the shell and enter and it opens the python shell.

  • Thanks! However this way I can't run a specific file in the shell. I am aware of "python myfile.py", but that quits python after the program is complete. I would like to be able to enter python even after the program is done, as is possible in IDLE. – lucafossen Oct 05 '21 at 18:25
  • You did not get my point, I meant to just write python in shell and press return and it will open the IDLE for you, and you can write the code you want. – Georges Chouchani Oct 06 '21 at 19:10
0

To the original question, yes you can interact with the console and run python files as if you were running them from the command line.

To your second query, VSCode has support for Jupyter notebook which is useful for running single lines of code. This may be what you're looking for

Jamie T
  • 56
  • 1
  • 6
  • Thanks for the response! I guess I should clarify what I'm looking for better: I'm essentially looking for the same behaviour as IDLE, where i can run a .py file and be able to input python into the shell, even after the program has completed. – lucafossen Oct 05 '21 at 18:23
  • I actually had a colleague recently who didn't want to leave IDLE for VSCode for this reason. Essentially you want access the variables after running the script? One option may be to use the debug mode in VSCode and line breaks to check outputs. I know it's not ideal. Otherwise does [this](https://stackoverflow.com/a/59016640/15565369) answer the question? – Jamie T Oct 05 '21 at 21:02
0

You can install Python Extension to run python shell file in vscode. Python Extension. You can open new terminal and go to the file location path in terminal, then you can run python shell file

  • Thanks, I am aware of this :) However I don't know if it's possible to run python files in vscode and be able to use the shell to interact with that program, even after the program has ended. I want the chevron prompt to still exist after the program is done. This functionality exists in IDLE and I often have to run my code in IDLE to use this feature. – lucafossen Oct 05 '21 at 18:29