Reading File Operation in Python
source link: http://uzairadamjee.com/blog/reading-file/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Reading File Operation in Python
This tutorial will cover another function of file handling i.e. Reading a file.
For reading a file we need to first open using ‘r’ mode which is used for reading.
file = open("abc.text", "r")
print (file.read())
print(file.readline())
read() returns whole string but we can also specify number of character which we want to read.
file.read(4) # read the next 4 data
Reading data by traversing and readline()
file = open("abc.text", "r")
print(file.readline())
#we can also print data by looping in file object
for d in file:
print(d)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK