user3426358 user3426358 - 11 months ago 69
Python Question

Remove \n from python string

I have scraped a webpage using beautiful soup.
I'm trying to get rid of a '

' character which isnt eliminated despite whatever I try.

My effort so far:



[u'\nWong; Voon Hon (Singapore, SG
Kandasamy; Ravi (Singapore, SG
Narasimalu; Srikanth (Singapore, SG
Larsen; Gerner (Hinnerup, DK
Abeyasekera; Tusitha (Aarhus N, DK

How do I eliminate the [u'\n? What am I doing wrong?

The full code is here.

Answer Source

You need to escape the newline character (double "\"):

for r in rep:

This is the same as @cricket_007's answer, however, the second part from his answer does not work for me. To my knowledge, str.replace() does not support these kind of regular expression lookups.