[英]How to ignore double quotes character in ppython string (as an input argument to a function"
I need to pass an argument to a function where the certain part of the input needs to be wrapped in double quotes so is then properly interpreted.我需要将一个参数传递给 function ,其中输入的某些部分需要用双引号括起来,然后才能正确解释。
The goal is that the string provided by user: input = "abc"-d is intepreted as: ""abc"-d"目标是用户提供的字符串: input = "abc"-d 被解释为: ""abc"-d"
Why?为什么? Because between " " you provide an expression where - is treated as a dash and not arithmetical minus.
因为在“”之间你提供了一个表达式,其中 - 被视为破折号而不是算术减号。 I need that to pass it finally as "\\\"abc\\\"-d"
我需要它最终将其传递为 "\\\\"abc\\\\"-d"
I did try我确实尝试过
r""a-b-c"-d"
but no luck.但没有运气。 Thanks for your suggestions!
感谢您的建议!
Please Try '""abc"-d"'请尝试 '""abc"-d"'
Suppose your function name is func()
, then in order to avoid this kind of problem, simply call the function like func(' "abc"-d')
.假设您的 function 名称是
func()
,那么为了避免此类问题,只需像func(' "abc"-d')
一样调用 function 即可。 So logic is that instead of using "
, simply use '
所以逻辑是,而不是使用
"
,只需使用'
You can define the String with ' ' for example:您可以使用 ' ' 定义字符串,例如:
input = '"a-b-c"-d'
another way is to put \ before the ".另一种方法是将 \ 放在 ".
for example:
input = "\"b\""
print(input)
will print "b"将打印“b”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.