[英]Why does PyCharm use double backslash to indicate escaping?
For instance, I write a normal string and another "abnormal" string like this: 例如,我写了一个普通字符串和另一个“异常”字符串,如下所示:
Now I debug it, finding that in the debug tool, the "abnormal" string will be shown like this: 现在我调试它,发现在调试工具中,“异常”字符串将显示如下:
Here's the question: 这是问题:
Why does PyCharm show double backslashes instead of a single backslash? 为什么PyCharm显示双反斜杠而不是单反斜杠? As is known to all,
\\'
means '
. 众所周知,
\\'
意味着'
。 Is there any trick? 有什么伎俩吗?
What I believe is happening is the '
in your c
variable string needs to be escaped and PyCharm knows this at runtime, given you have surrounded the full string in "
(You'll notice in the debugger, your c
string is now surrounded by '
). To escape the single quote it changes it to \\'
, but now, there is a \\
in your string that needs escaping, and to escape \\
in Python, you type \\\\
. 我相信正在发生的是
'
你的c
变量字符串需要被转义并且PyCharm在运行时知道这一点,因为你已经包围了完整的字符串"
(你会在调试器中注意到,你的c
字符串现在被'
包围'
)。为了逃避它改变它的单引号\\'
,但现在,有一个\\
在字符串中需要转义,并逃避\\
Python中,键入\\\\
。
EDIT Let me see if I can explain the order of escaping going on here. 编辑让我看看我是否可以解释在这里逃避的顺序。
"u' this is not normal"
is assigned to c
"u' this is not normal"
被分配给c
c
to 'u' this is not normal'
at runtime. c
的字符串转换为'u' this is not normal'
。 See how, without escaping the 2nd '
, your string is now closed off right after u
. '
,你的字符串现在在u
之后立即关闭。 '
automatically for you by adding a slash before it. '
通过之前增加一个斜杠自动为您。 The string is now 'u\\' this is not normal'
. 'u\\' this is not normal'
。 At this point, everything should be fine but PyCharm may be taking an additional step for safety. 'u\\\\' this is not normal'
. 'u\\\\' this is not normal'
。 It is likely a setting inside PyCharm. 它可能是PyCharm中的一个环境。 Does it cause an actual issue with your code?
它是否会导致代码出现实际问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.