views:

161

answers:

1

I wanted to embed <p> tag where ever there is a \r\n\r\n.

u"Finally Sri Lanka showed up, prevented their first 5-0 series whitewash, and stopped India at nine ODI wins in a row. \r\n\r\nFor 62 balls Yuvraj Singh played a dream knock, keeping India in the game despite wickets falling around him. \r\n\r\nPerhaps the toss played a big part. This was only the second time Mahela Jayawardene beat Mahendra Singh Dhoni with the coin in the last 11 occasions. \r\n\r\nIt was Jayasuriya who provided Sri Lanka with the springboard. \r\n\r\nThe pyrotechnics may have stopped upon Jayasuriya's dismissal, but the runs kept coming at a fair pace."

I tried solving this using BeautifulSoup but couldn't find the way out of it. Can anyone through some light on this. Thanks in advance.

+4  A: 
''.join('<p>%s</p>' % line for line in text.split('\r\n\r\n'))
# Results:
u"<p>Finally Sri Lanka showed up, prevented their first 5-0
series whitewash, and stopped India at nine ODI wins in a row. </p>
<p>For 62 balls Yuvraj Singh played a dream knock, keeping India in the 
game despite wickets falling around him. </p><p>Perhaps the toss played
a big part. This was only the second time Mahela Jayawardene beat Mahendra
Singh Dhoni with the coin in the last 11 occasions. </p>
<p>It was Jayasuriya who provided Sri Lanka with the springboard. </p>
<p>The pyrotechnics may have stopped upon Jayasuriya's dismissal, but 
the runs kept coming at a fair pace.</p>"
nosklo
awesome, Thanks :)
aatifh
you prob could add space to the split separator, just to make it cleaner
SilentGhost
@SilentGhost: That would work with the sample text, but is not what was asked. Maybe using '<p>%s</p>' % line.strip()...
nosklo