Delete newline / return carriage in file output

后端 未结 6 1530
无人及你
无人及你 2020-12-16 16:55

I have a wordlist that contains returns to separate each new letter. Is there a way to programatically delete each of these returns using file I/O in Python?

Edit

6条回答
  •  一个人的身影
    2020-12-16 17:42

    You can use a string's rstrip method to remove the newline characters from a string.

    >>> 'something\n'.rstrip('\r\n')
    >>> 'something'
    

提交回复
热议问题