Operating environment
Python3 (ideone)
link
https://docs.python.jp/3/library/io.html
code
http://ideone.com/KLd4OP
import io
emuCsv = """1,2,3
4,5,6
7,8,9"""
print('begin')
with io.StringIO(emuCsv) as fin:
print(fin.read())
print('end')
run
begin
1,2,3
4,5,6
7,8,9
end
v0.2
http://ideone.com/Qu0vZr
import io
emuCsv = """1,2,3
4,5,6
7,8,9"""
print('begin')
with io.StringIO(emuCsv) as fin:
print('line9')
print(fin.read())
print('end')
run
begin
line9
1,2,3
4,5,6
7,8,9
end
In fin.read ()
, 3 lines are printed () at a time.
In the above case, it doesn't seem to make sense to use the with syntax.
There seems to be readline (). https://stackoverflow.com/questions/7472839/python-readline-from-a-string
http://ideone.com/hi1DN7
import io
emuCsv = """1,2,3
4,5,6
7,8,9"""
print('begin')
fin = io.StringIO(emuCsv)
print(fin.readline(),end='')
print(fin.readline(),end='')
print(fin.readline())
print('end')
run
begin
1,2,3
4,5,6
7,8,9
end
You can run readline () a fixed number of times. Unknown about EOF.
Recommended Posts