【问题标题】:Run Python in VSCode in python shell like IDLE在像 IDLE 这样的 Python shell 中在 VSCode 中运行 Python
【发布时间】:2020-02-21 17:23:16
【问题描述】:

我很了解线程How to execute Python code from within Visual Studio Code

但它们都没有显示如何让 >>> python shell 与导入的文件一起运行。因为我想单独调用函数。 我知道我可以通过在终端中简单地输入python 来启动python shell,但是python文件中的函数每次都必须手动导入。

有没有办法像在 IDLE 中一样在 VSCode 中运行文件?

【问题讨论】:

    标签: python visual-studio-code python-idle


    【解决方案1】:

    Ctrl+Shift+P (Command+Shift+P) 并输入 Python: Start REPL。单击该命令,您将获得一个交互式 Python 控制台。

    【讨论】:

      【解决方案2】:

      您可以使用参数 -i 在 VSC 代码终端中以交互模式运行文件: python -i py_file.py

      【讨论】:

      • @xnegra80 这应该是公认的答案。
      【解决方案3】:

      假设您安装了官方 Python 扩展,您可以在命令列表 (Ctrl+Shift+P) 中搜索“Python 交互”,您会看到几个选项可以对此进行不同的变体:

      【讨论】:

      • 它会打开 jupyter,我认为这不是我想要的。有什么办法可以解决吗?
      猜你喜欢
      • 2017-12-30
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多