To add a new line before a set of characters in a line using python

Viewed 3159

I have a line of huge characters in which a set of characters keep repeating. The line is : qwethisistheimportantpartqwethisisthesecondimportantpart

There are no spaces in the string. I want to add a new line before the string 'qwe' so that I can distinguish every important part from the other.

Output :

qwethisistheimportantpart
qwethisisthesecondimportantpart

I tried using

for line in infile:
    if line.startswith("qwe"):
        line="\n" + line

and it doesn't seem to work

3 Answers
Related