如何在VS Code中调试时提供输入数据?

问题描述 投票:1回答:1

我想知道在VS Code中调试时如何提供数据。例如。

a = input()
b = input()

c = a + b

print(c)

我还有一个input.txt文件,如下所示:

10
20

因此,当我运行python test.py < input.txt时,代码应该读取数据并运行。

但是在调试时如何告诉调试器使用输入?

python visual-studio-code vscode-debugger
1个回答
0
投票

使用externalConsole": true创建调试配置。查看Igor的解决方案以获取更多信息。从文本文件中读取输入对input()不起作用,但您可以使用sys.argv[]作为应用程序参数提供。

screenshot of test code.

这是我用外部调试运行代码的时候。

© www.soinside.com 2019 - 2024. All rights reserved.