Looking at f
objects in python 2.7 vs 3.5, they are slightly different
Following
with open('tmp.txt','r') as f: print(f) print(type(f))
In python 2.7 returns
<open file 'tmp.txt', mode 'r' at 0x0000000003DD9780> <type 'file'>
While in python 3.5 it returns
<_io.TextIOWrapper name='tmp.txt' mode='r' encoding='cp1252'> <class '_io.TextIOWrapper'>
The same behavior can be obtained in python 2.7 using
import io with io.open('tmp.txt','r') as f: while True: for line in f: print(line.replace('\n',''))
source share