Ale*_*kin 5 python stdin visual-studio-code
我正在使用 Visual Studio Code 来调试我的 Python 代码。
我想重定向一个文本文件stdin并将输出写入另一个文件。
我可以通过使用以下语法直接运行 python 来实现:
python code.py < input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)
有没有办法在调试脚本时允许这样做?如果这是不可能的,我可以创建一个配置来使用该参数运行 python。我尝试在 中使用args参数launch.json,但这些参数都放在引号中,这与重定向的目的背道而驰。
我能够使用launch.json配置文件中的args参数来实现这一点:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": [ "<", "input.txt",
">", "output.txt" ]
}
]
}
Run Code Online (Sandbox Code Playgroud)
运行调试器时,您会看到以下命令行:
bash-3.2$ env DEBUGPY_LAUNCHER_PORT=51669 /usr/local/opt/python/bin/python3.7 /Users/XXXX/.vscode/extensions/ms-python.python-2020.4.76186/pythonFiles/lib/python/debugpy/wheels/debugpy/launcher "/Users/XXXX/my_script.py" < input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)
Visual Studio 代码 1.45
macOS 10.14.6
| 归档时间: |
|
| 查看次数: |
3739 次 |
| 最近记录: |