Python: read text variable line by line (not file)

Viewed 932

I do have:

url="https://mywebpage.com/content"
text=requests.get(url,stream=True).text

for line in text:
  print "Line "+line

I got each letter in a different line (instead of line). I also can not use iterator req.iter_lines because I need to process the results multiple times looking for different data.

Any hints?

1 Answers

You should use split and strip, in case you have windows style line breaks (\r)

for line in text.split('\n'):
  line = line.strip('\r')
  print ("Line "+line)
Related