What substitutes xreadlines() in Python 3? What substitutes xreadlines() in Python 3? python-3.x python-3.x

What substitutes xreadlines() in Python 3?


The file object itself is already an iterable.

>>> f = open('1.txt')>>> f<_io.TextIOWrapper name='1.txt' encoding='UTF-8'>>>> next(f)'1,B,-0.0522642316338,0.997268450092\n'>>> next(f)'2,B,-0.081127897359,2.05114559572\n'

Use itertools.islice to get an arbitrary element from an iterable.

>>> f.seek(0)0>>> next(islice(f, 7, None))'8,A,-0.0518101108474,12.094341554\n'


how about this (generator expression):

>>> f = open("r2h_jvs")>>> h = (x for x in f)>>> type(h)<type 'generator'>`