File IO

In [38]:
f=open('data.txt')
print(type(f))

for s in f:
    print(s,end='')
<class '_io.TextIOWrapper'>
This is line 1.
Second line.
Last line.
In [34]:
f=open('outdata.txt','w')

for i in range(5):
    f.write('This is line {}\n'.format(i))

f.close()
In [39]:
for s in open('outdata.txt'):
    print(s,end='')
This is line 0
T