python - 如何调试/启动具有包含“<”和“>”的参数的程序
问题描述
我有一个处理 HTML 内容的程序。使用命令行参数,我可以给它提供测试字符串。
从 Windows 命令行 (cmd.exe) 我可以毫无问题地运行它
C:\Python36\python.exe program.py -t "<head><title>Test</title></head>"
我无法获得可以正确传递此参数的启动配置。
我收到以下错误
< was unexpected at this time.
或者
The system cannot find the file specified.
没有提到它正在寻找的文件
该问题可能是由于所有内容都作为参数传递给 cmd 引号内的事实引起的。
我使用添加了选项的标准Python: Current File
配置args
{
"name": "Python: Debug with args",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args" : ["-t","<head><title>Test</title></head>"]
}
使用单转义添加引号
"args" : ["-t","\"<head><title>Test</title></head>\""]
或双重转义(在 C++ 启动文档中找到)
"args" : ["-t","\\\"<head><title>Test</title></head>\\\""]
没有解决问题。
编辑
部分解决方案,仅适用于新终端:
在参数字符串中添加一个空格 ==> VSC 将参数转义为双引号
"args" : ["-t","<head><title>Test</title> </head>"]
我曾经读过一些关于让 VSC 将参数用单引号或双引号括起来的文档。但是我在当前版本中找不到这个文档了。
解决方案
如果您尝试像这样设置参数怎么办:
"args" : '-t "<head><title>Test</title></head>"'
代替
"args" : ["-t","<head><title>Test</title></head>"]
推荐阅读
- docker - Docker Compose 按需激活容器
- windows - Windows 7 上通过蓝牙的串行通信有间歇性数据丢失
- angularjs - 带有OR条件的正则表达式在angularjs中不起作用
- php - [Microsoft][ODBC Driver 11 for SQL Server]TCP 提供程序:超时错误 [258]。
- html - 如果仅在 html 中屏幕尺寸小于 768px,则在特定位置将行拆分为 2
- qgis - QGIS不会导入这行WKT我不知道为什么
- c# - 如何用 IndexOf() 替换 Contains()
- python - 如何用逗号分隔csv
- javascript - 在复选框单击时隐藏/显示 div
- python - 如何使用 pygame.USEREVENT 让敌人定期开火