Pycharm 删除参数字段中的引号
Pycharm deletes quotation marks in paramenter field
我想使用 PyCharm 中的参数字段为 python 脚本设置参数。
我的配置:
但是运行控制台中的命令是:
python3 path_to_script.py '{app_id: picoballoon_network, dev_id: ferdinand_8c ... and so on
而不是:
python3 path_to_script.py '{"app_id": "picoballoon_network", "dev_id": "ferdinand_8c" ... and so on
基本上,它删除了参数中的所有"
。
有谁知道如何关闭它?
我的 PyCharm 版本是:
PyCharm 2020.3.1 (Professional Edition)
Build #PY-203.6682.86, built on January 4, 2021
Runtime version: 11.0.9.1+11-b1145.37 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
为避免引号被删除,请注意编写包含引号的参数的规则。
Run/Debug Configuration: Python
When specifying the script parameters, follow these rules:
Use spaces to separate individual script parameters.
Script parameters containing spaces should be delimited with double quotes, for example, some" "param
or "some param"
.
If script parameter includes double quotes, escape the double quotes with backslashes, for example:
-s"main.snap_source_dirs=[\"pcomponents/src/main/python\"]" -s"http.cc_port=8189"
-s"backdoor.port=9189"
-s"main.metadata={\"location\": \"B\", \"language\": \"python\", \"platform\": \"unix\"}"
问题中的案例将是单个参数,让我们将规则应用于示例:
'{"app_id": "picoballoon_network", "dev_id": "ferdinand_8c"'
因为它是一个包含空格的参数,所以必须用引号括起来。
由于参数的内容还包含引号,因此必须使用反斜杠对其进行转义\
。所以应用参数格式规则给出:
"'{\"app_id\": \"picoballoon_network\", \"dev_id\": \"ferdinand_8c\"}'"
- (旁注): 在示例中,参数被 Apostrophes, this may be unnecessary and will probably have to be stripped later in your Python code (the below example uses the
strip
方法包围)。
您可以使用这个简单的脚本对其进行测试:
import sys
import ast
your_dictionary = ast.literal_eval(sys.argv[1].strip("'"))
(旁注):您的示例参数是一个包含 Python dictionary, there are several ways to convert it, in the example I included the highest voted answer from this question: "Convert a String representation of a Dictionary to a dictionary?"
的字符串
使用中的参数和测试代码截图:
我想使用 PyCharm 中的参数字段为 python 脚本设置参数。
我的配置:
但是运行控制台中的命令是:
python3 path_to_script.py '{app_id: picoballoon_network, dev_id: ferdinand_8c ... and so on
而不是:
python3 path_to_script.py '{"app_id": "picoballoon_network", "dev_id": "ferdinand_8c" ... and so on
基本上,它删除了参数中的所有"
。
有谁知道如何关闭它?
我的 PyCharm 版本是:
PyCharm 2020.3.1 (Professional Edition)
Build #PY-203.6682.86, built on January 4, 2021
Runtime version: 11.0.9.1+11-b1145.37 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
为避免引号被删除,请注意编写包含引号的参数的规则。
Run/Debug Configuration: Python
When specifying the script parameters, follow these rules:
Use spaces to separate individual script parameters.
Script parameters containing spaces should be delimited with double quotes, for example,
some" "param
or"some param"
.If script parameter includes double quotes, escape the double quotes with backslashes, for example:
-s"main.snap_source_dirs=[\"pcomponents/src/main/python\"]" -s"http.cc_port=8189" -s"backdoor.port=9189" -s"main.metadata={\"location\": \"B\", \"language\": \"python\", \"platform\": \"unix\"}"
问题中的案例将是单个参数,让我们将规则应用于示例:
'{"app_id": "picoballoon_network", "dev_id": "ferdinand_8c"'
因为它是一个包含空格的参数,所以必须用引号括起来。
由于参数的内容还包含引号,因此必须使用反斜杠对其进行转义
\
。所以应用参数格式规则给出:
"'{\"app_id\": \"picoballoon_network\", \"dev_id\": \"ferdinand_8c\"}'"
- (旁注): 在示例中,参数被 Apostrophes, this may be unnecessary and will probably have to be stripped later in your Python code (the below example uses the
strip
方法包围)。
您可以使用这个简单的脚本对其进行测试:
import sys
import ast
your_dictionary = ast.literal_eval(sys.argv[1].strip("'"))
(旁注):您的示例参数是一个包含 Python dictionary, there are several ways to convert it, in the example I included the highest voted answer from this question: "Convert a String representation of a Dictionary to a dictionary?"
的字符串使用中的参数和测试代码截图: