[英]python print escape backslash
我需要python來生成完全這樣的字符串文字:
e.b=\"e\"
但是我不知道該怎么做。 我正在嘗試:
r'e.b=\"e\"' => e.b=\\"e\\"
"""e.b=\"e\"""" => e.b="e"
還有許多其他可能性,但最終都以eb = \\“ e \\”開頭
有任何想法嗎?
好吧,您第一次做對了,只是您檢查了創建的字符串的repr
,而不是字符串本身:
s = r'e.b=\"e\"'
s # this is the repr() of the string
=> 'e.b=\\"e\\"'
print(repr(s))
=> 'e.b=\\"e\\"'
print(s) # this is what you want
=> e.b=\"e\"
底線s=r'e.b=\\"e\\"'
。
您是否在考慮像這樣打印?
import re
d = re.escape(r'e.b=\"e\"')
print d
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.