Iterating over a stream with only readline() method [newbie question]
Syam Pannala
syam at c544784-a.stcla1.sfba.home.com
Sat Oct 7 01:08:10 EDT 2000
[Newbie Alert!!]
hi,
i have a stream which provides only a readline() method (it can come from
a variety of sources including network and i dont want to buffer it so
that i can implement readlines()).
What is the python idiom for iterating over this stream until it throws
EOFError ?
thanks,
syam
To elobarate, if it had readlines(), i would have said
for i in stream.readlines():
..use i ..
i want the ..use i.. code not to change very much. Also, i think
while 1:
try:
i = stream.readline()
expcept EOFError:
break
... use i ..
looks very inelegant, even though that is what i have used as the current
implementation.
thanks again.
More information about the Python-list
mailing list