我想知道在VS Code中调试时如何提供数据。例如。
a = input()
b = input()
c = a + b
print(c)
我还有一个input.txt文件,如下所示:
10
20
因此,当我运行python test.py < input.txt
时,代码应该读取数据并运行。
但是在调试时如何告诉调试器使用输入?
使用externalConsole": true
创建调试配置。查看Igor的解决方案以获取更多信息。从文本文件中读取输入对input()
不起作用,但您可以使用sys.argv[]
作为应用程序参数提供。
这是我用外部调试运行代码的时候。