<p>我正在尝试删除Linux上Python2.7中的所有空格/制表符/换行符。</p>
<p>我写了这篇文章,它应该可以完成这项工作:</p>
<pre><code>myString="I want to Remove all white \t spaces, new lines \n and tabs \t"
myString = myString.strip(' \n\t')
print myString
</code></pre>
<p>输出:</p>
<pre><code>I want to Remove all white spaces, new lines
and tabs
</code></pre>
<p>这似乎是一件简单的事情,但我在这里错过了一些东西。我应该进口点什么吗?</p>
<pre><code>import re
mystr = "I want to Remove all white \t spaces, new lines \n and tabs \t"
print re.sub(r"\W", "", mystr)
Output : IwanttoRemoveallwhitespacesnewlinesandtabs
</code></pre>