【发布时间】:2022-06-18 08:25:53
【问题描述】:
抱歉,如果这已经解决,但我无法找到解决方案。我正在尝试像在 IDLE 中一样运行我的 python 文件。我记得在以前的设备中,我以某种方式更改了设置,因此我能够从正在运行的 python 文件中输入终端函数,它会运行该函数。
例子:
def main ():
def function_2 ():
print ('Value of x at start of the function: ', x)
x = x + 10
print ('Value of x at end of the function: ', x)
x = 5
print ('Value of x in main before calling function: ', x)
function_2()
print ('Value of x in main before calling function: ', x)
在 IDLE 中,我会运行 python 文件,然后在空闲终端中运行 main(),它就会运行。我也想做同样的事情,但使用 VS Code。任何帮助,将不胜感激。非常感谢。
【问题讨论】:
-
从 IDLE 编辑器运行文件时,IDLE 运行它的方式与使用
python -i path/to/file从命令行相同。-i表示在运行文件并将输出打印到 Python Shell 后,在交互式 shell 中打印交互式提示。除非 VS 代码以某种方式做同样的事情,否则没有地方可以输入诸如main()之类的 python 语句。
标签: python visual-studio-code python-idle