2013-03-29 18 views
0
u'The disclosure relates to systems and methods for detecting features on\n  billets  of laminated veneer lumber (LVL). In some embodiments, an LVL\n  billet is provided and passed through a scanning assembly. The scanning\n  assembly includes anx-raygenerator and anx-raydetector. Thex-raygenerator generates a beam ofx-rayradiation and thex-raydetector\n  measures intensity of the beam ofx-rayradiation after is passes through\n  the LVL billet. The measured intensity is then processed to create an\n  image. Images taken according to the disclosure may then be analyzed todetectfeatures on the LVL billet.' 

以上是我的输出结果。 现在我想摆脱Python中的“\ n”。如何摆脱我的python输出中的“ n”

我该如何认识到这一点? 我应该使用re模块吗? 我用text来代表上面的所有文字,text.strip("\n")根本没有用处。 为什么?

谢谢!

+0

改变变量名'text'因为'str'阴影内建的'str' – jamylak

回答

0

试试这个

''.join(a.split('\n')) 

一个是输出字符串

+0

宾果!这也很有用!谢谢! – sikisis

+0

在这种情况下,你不应该使用这个,'replace'是要走的路。 – jamylak

6

对于字符串,s,这样做的:

s = s.strip("\n") 

只会去掉开头和结尾的换行符。

你想要的是

s = s.replace("\n", "") 
+1

没错!这是有帮助的!谢谢! – sikisis

1

您是否尝试过的替换功能?

s = u'The disclosure relates to systems and methods for detecting features on\n  billets  of laminated veneer lumber (LVL). In some embodiments, an LVL\n  billet is provided and passed through a scanning assembly. The scanning\n  assembly includes anx-raygenerator and anx-raydetector. Thex-raygenerator generates a beam ofx-rayradiation and thex-raydetector\n  measures intensity of the beam ofx-rayradiation after is passes through\n  the LVL billet. The measured intensity is then processed to create an\n  image. Images taken according to the disclosure may then be analyzed todetectfeatures on the LVL billet.' 

s.replace('\n', '') 
+0

宾果!我知道了。是的,那很有用。不错,我是一个绿手。感谢您的帮助。 – sikisis

+0

不错的一个!也是一个绿手,发现SO令人难以置信的上瘾 –

-1
str = 'The disclosure relates to systems and methods for detecting features on\n  billets  of laminated veneer lumber (LVL).' 
str.replace('\n', '') 
' '.join(str.split()) 

输出

The disclosure relates to systems and methods for detecting features on billets of laminated veneer lumber (LVL). 
+0

yeah.thas的最佳输出形式 – sikisis