Can't delete "\r\n" from a string

Viewed 25074

I have a string like this:

la lala 135 1039 921\r\n

And I can't remove the \r\n.

Initially this string was a bytes object but then I converted it to string

I tried with .strip("\r\n") and with .replace("\r\n", "") but nothing...

4 Answers

'\r\n' is also a standard line delimiter for .splitlines(), so this can also work.

>>> s = "la lala 135 1039 921\r\n"
>>> type(s)
<class 'str'>
>>> t = ''.join(s.splitlines())
>>> t
'la lala 135 1039 921'
>>> type(t)
<class 'str'>
Related