def __init__(self, text):
self.text = text.strip("\r").strip("\n").strip("\r").strip(" ")
print("TEXT:"+text+";SELFTEXT:"+self.text)
text
被称为“http://thehill.com/homenews/senate/376515-jeff-flake-there-will-be-a-republican-challenger-to-trump-in-2020 \ r \ n”,而self.text
仍然是相同的(不会删除\r
和\n
)。
当这个代码放在Shell for Python上时,它可以根据需要运行。有任何想法吗?
编辑:当print语句更改为print时(“REPR:”+ repr(text)+“\ TEXT:”+ text“; SELF TEXT:”+ self.text)
类似字符串的输出是:
REPR:'http://thehill.com/homenews/senate/376548-lindsey-graham-war-with-north-korea-would-be-worth-it-in-the-long-run\r\n'文字:http://thehill.com/homenews/senate/376548-lindsey-graham-war-with-north-korea-would-be-worth-it-in-the-long-run \ r \ n; SELFTEISXT:http://thehill.com/homenews/senate/376548-lindsey-graham-war-with-north-korea-would-be-worth-it-in-the-long-run \ r \ n
试试这个:
text.replace("\r\n","")
尝试使用原始字符串。我在qazxsw poi中添加了qazxsw poi
EX:
"r"
输出:
replace(r"\r\n", "")