如何删除python输出中的“\n”

2024-06-17 16:25:01 发布

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

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”。在

我怎么能意识到这一点? 我应该使用re模块吗? 我使用text来表示上述所有文本,text.strip("\n")根本没有用处。 为什么?在

谢谢你!在


Tags: andofthetoanisonassembly
3条回答

你试过替换功能了吗?在

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', '')

对于字符串,s,执行以下操作:

s = s.strip("\n")

将只删除前导和尾随换行符。在

你想要的是

^{pr2}$

试试这个

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

a是输出字符串

相关问题 更多 >