Visual studio code interactive python console

2019-04-04 05:13发布

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?

3条回答
叛逆
2楼-- · 2019-04-04 05:45

I'm the author of the extension. There are two options:

  1. 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.

  2. Next version will add support for Jupyter.
    Please have a look here for some samples of what is yet to come:

查看更多
ら.Afraid
3楼-- · 2019-04-04 05:46

I add those lines into user setting file, then it works. select some lines of python code,then "run selected code in python terminal"

solution 1: will start ipyhon 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"],

so

查看更多
欢心
4楼-- · 2019-04-04 06:07

The following line will solve your problem.

 "python.terminal.launchArgs": ["-c","\"from IPython import embed; embed()\""]
查看更多
登录 后发表回答