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" を削除したいと考えています。

どうすればこれを理解できますか?re モジュールを使用する必要がありますか? 私textは上記のすべてのテキストを表すためにtext.strip("\n")使用し、まったく役に立ちません。なんで?

ありがとう!

4

4 に答える 4

6

文字列 の場合s、次のように実行します。

s = s.strip("\n")

先頭と末尾の改行文字のみを削除します。

あなたが欲しいのは

s = s.replace("\n", "")
于 2013-03-29T09:42:53.223 に答える
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', '')
于 2013-03-29T09:45:32.720 に答える
0

これを試して

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

a は出力文字列です

于 2013-03-29T09:43:15.940 に答える
-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).
于 2013-03-29T09:45:56.780 に答える