.strip(“\n”)未从字符串中删除“\n”

2024-07-07 07:19:56 发布

您现在位置:Python中文网/ 问答频道 /正文

 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和{})。在

当这段代码被放到Python的Shell中时,它就可以正常工作了。 有什么想法吗?在

编辑:当打印语句更改为 打印(“REPR:”+REPR(文本)+“\n文本:“+text+”;SELFTEISXT:”+自我.text)在

类似字符串的输出为:

代表:'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


Tags: textin文本selfcomhttpwithbe