In [1]:
from io import StringIO

In [2]:
s = (
'''hello
world
''')
s


Out[2]:
'hello\nworld\n'

In [3]:
f = StringIO(s)
f


Out[3]:
<_io.StringIO at 0x7fbdb00cd5e8>

In [4]:
for line in f:
    print(repr(line))


'hello\n'
'world\n'

In [5]:
with StringIO(s) as f:
    for line in f:
        print(repr(line))


'hello\n'
'world\n'