TECHIES WORLD

For Techs.... Techniques.... Technologies....

LinuxPython

How to read the content of a file in Python

We can read the content of a file using either one of the method given below.

f = open('myfile','r')
print f.read()

OR

with open('myfile') as f
print f.read()

If the file need to be read line by line,

f = open('myfile','r')
print f.readlines()

 

Leave a Reply