Posted By

kennym on 10/17/10


Tagged

python replace text


Versions (?)

Add a at the beginning of each line


 / Published in: Python
 

  1. # Given some text with newlines:
  2. text = "hello\nworld\n!!!"
  3.  
  4. # Add a tab before every newline:
  5. "\t" + text.replace("\n", "\n\t")

Report this snippet  

You need to login to post a comment.