$ cat file Unix Linux AIX1. Reading line by line:
>>> fd = open('/home/guru/file', 'r')
>>> for line in fd:
... print(line)
...
Unix
Linux
AIX
>>>
open function opens a file and returns a file object. Arguments are filename and the mode, 'r' for reading. When the file object is traversed, every iteration reads a line and line gets printed. Notice the blank line after every print. This is because the variable line contains a newline character read from the file and print function adds another newline.