Input from a file

Input from a file

1
%cat /tmp/test.txt
Copied!
Output:
1
1 2 3 4 5
2
6 7 8 9 10
Copied!
1
with open('/tmp/test.txt','r') as fp:
2
while True:
3
line=fp.readline()
4
if line:
5
line=line.strip('\n')
6
print(line.split(' '))
7
else:
8
break
Copied!
Output:
1
['1', '2', '3', '4', '5']
2
['6', '7', '8', '9', '10']
Copied!
Last modified 1yr ago
Copy link