为什么替换不能使用此字符串?
[' Python \ xc3 \ xa9 uma linguagem de programa \ xc3 \ xa7 \ xc3 \ xa3o de alto n \ xc3 \ xadvel']
上面的字符串来自nltk,请遵循以下代码:
# - * - coding: utf-8 - * -
import nltk
text = 'Python is a high-level programming language'
val = str(nltk.tokenize.sent_tokenize (text))
val = val.replace('\xc3\xa9', 'é')
print val
答案 0 :(得分:0)
试试这个:
var myMappedImages = document.getElementsByClassName("myMappedImage");
for(var i=0,len=myMappedImages.length;i<len;i++){
myMappedImages[i].usemap = "#myimagemap";
}
或
val = val.replace(r'\xc3\xa9', 'é')
因为val = val.replace('\\xc3\\xa9', 'é')
是转义字符。
What exactly do “u” and “r” string flags do in Python, and what are raw string literals?这可能会有所帮助。