简体   繁体   English

如何忽略 ppython 字符串中的双引号字符(作为函数的输入参数)

[英]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.

相关问题 带双引号的 JSON 输入字符串 - JSON input string with double quotes 如何在 python 中获取字符串周围的双引号以返回 function? 不允许输入/输出操作 - How do I get double quotes around string in return function, in python? Input/output operations are not allowed python中是否有一个函数(或如何)以类似字典的字符串转义双引号? - is there a function in python (or how ) to escape a double quotes in dictionary-like string? 如何使用输入 function 来询问路径名并将其保存在双引号而不是单引号中? - How can I use the input function to ask for the Pathname and save it within double quotes instead of single quotes? python在输入值中带双引号的字符串 - String with double quotes inside input value in python 在逗号上分割字符串,但忽略双引号内的逗号? - Split string on commas but ignore commas within double-quotes? 如何在双引号中打印字符串? (不打印双引号) - How do I print a string in double quotes? (NOT PRINT DOUBLE QUOTES) 将分隔的字符串拆分为字典但忽略双引号之间的“相等”,在 Python 中 - Splitting a separated string to a dictionary but ignore the "equal" between double quotes, in Python 如果在双引号之外,Python替换字符串,否则忽略 - Python Replace string if outside double quotes else ignore Python csv 阅读器忽略作为字符串一部分的双引号内的分隔符 - Python csv reader ignore delimiters within double quotes that are part of a string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM