【发布时间】:2012-05-29 11:31:39
【问题描述】:
我正在尝试在 Linux 上删除 python 2.7 中的所有空格/制表符/换行符。
我写了这个,应该做的工作:
myString="I want to Remove all white \t spaces, new lines \n and tabs \t"
myString = myString.strip(' \n\t')
print myString
输出:
I want to Remove all white spaces, new lines
and tabs
这似乎是一件简单的事情,但我在这里缺少一些东西。我应该导入一些东西吗?
【问题讨论】:
-
查看这个相关问题的答案:stackoverflow.com/questions/1185524/…strip() 只删除前导和尾随字符,而不是所有字符。
-
这对我有用,来自:[如何修剪空白(包括制表符)?][1] s = s.strip(' \t\n\r') [1]: @ 987654323@
标签: python string python-2.7 strip