File IO

In [6]:
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.
See, one more.
In [7]:
f=open('outdata.txt','w')

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

f.close()
In [9]:
for s in open('outdata.txt'):
    print(s)
This is the line 0

This is the line 1

This is the line 2

This is the line 3

This is the line 4

This is the line 5

This is the line 6

This is the line 7

This is the line 8

This is the line 9

In [ ]: