May 2017
Intermediate to advanced
280 pages
6h 2m
English
In order to read the file line by line, use readline().
Let's see the sample code readline1.py:
file_input = open("sample1.txt",'r')print file_input.readline()print file_input.readline()print file_input.readline()file_input.close()
Let's see the output of code:

In code, we have printed three lines. What happens, if you specify count in readline(count). See the code readlinecount.py:
file_input = open("sample1.txt",'r')print file_input.readline(100)print file_input.readline(20)file_input.close()
Let's see the output:
In the file_input.readline(100) syntax prints 100 characters of the first line. But the first line ...
Read now
Unlock full access