I want to write a string to a StringIO() object and then read it line by line; I tried two ways and none of them produced any output. What am I doing wrong?
Creating object, writing to it and check if it worked:
from io import StringIO
temp=StringIO()
temp.write("This is a \n test sentence\n!")
temp.getvalue() --> 'This is a \n test sentence\n!'
Approach one:
for line in temp:
print(line)
Approach two:
test = True
while test:
line = temp.readline()
if not line:
test=False
else:
print(line)