从spam\/eggs
到spam/eggs
# This isn't working...
str = "spam\/eggs"
s = bytes(str, "utf-8").decode("unicode_escape")
print(s)
>>> spam\/eggs
# How to get "spam/eggs"
从spam\/eggs
到spam/eggs
# This isn't working...
str = "spam\/eggs"
s = bytes(str, "utf-8").decode("unicode_escape")
print(s)
>>> spam\/eggs
# How to get "spam/eggs"
string = 'spam\\/eggs'
我认为这不是最高效的方法,但你也可以这样做:strs = 'spam\/eggs'
print(strs)
strs = strs.replace('\\','')
print(strs)
\
。import re
myString = "spam\/eggs"
str2 = re.sub(r'\\', "", myString) # remove this character '\'
print(str2)
# spam/eggs
import re
myString = "sp&a+m\/eg*gs"
str2 = re.sub(r'[\\&+*]', "", myString) # to remove what you want into the brackets
print(str2)
# spam/eggs
str2 = re.sub(r'\\/', "/", myString)
适用于通用目的。 - wongzstr = "spam/eggs"
str2 = bytes(str, "utf-8").decode("unicode_escape")
print(str2)
顺便说一句:您应该更加仔细地将代码放在问题中;您先是称一个变量为str
,然后又称其为myString
,第二个变量则先是str2
,然后变成了str1
"spam/eggs".encode().decode()
是否回答了您的问题? - Chiheb Nexusbytes("spam/eggs", "utf-8").decode("unicode_escape") == "spam/eggs"
- erip