-3

I have a single, very long string that s output from a python function and need to split it onto multiple lines each time a \n is found.

I know I can use regex, but I'm not entirely sure how.

Any help would be much appreciated!

Thanks in advance.

S tommo
  • 165
  • 2
  • 5
  • 15
  • 3
    Possible duplicate of [Split string using a newline delimeter with Python](http://stackoverflow.com/questions/22042948/split-string-using-a-newline-delimeter-with-python) – Chris_Rands Jan 12 '17 at 11:13
  • This question does not solve my issue. I have a single string I need to split by the characters mentioned – S tommo Jan 12 '17 at 11:24

1 Answers1

1

I think, you don't have to use regex to solve your this task because it may work too slow for big strings. I would use io.StringIO (or StringIO.StringIO if you're using Python 2.7) to process your string:

from io import StringIO

s = "qwe\nrty\nuio"

s_stream = StringIO(s)
for line in s_stream:
    print(line) # it prints data line by line
s_stream.close()
Fomalhaut
  • 8,590
  • 8
  • 51
  • 95