Python remove line breaks -


this question has answer here:

i'm reading output program this

test_output = test_run.communicate(input=str.encode(input))[0] output = test_output .decode('utf-8').strip() 

and if program returns new line this

>>> >>> b 

it reads this(with repr())

>>> 'a\r\nb' 

i tried removing line breaks

output.replace(r"\r\n","") 

but it's not working, if print regular string returns

>>> >>> b 

and repr()

>>> 'a\r\nb' 

how can remove \r\n string?

don't use regexp, regexp doesn't think does:

>>> 'a\r\nb'.replace('\r\n', '') 'ab' 

i.e. remove r in replace(r'\r\n', '')


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -