6

Reading File Operation in Python

 3 years ago
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.
neoserver,ios ssh client
Reading File Operation in Python
FILE-HANDLING-IN-PYTHON.png

Reading File Operation in Python

September 13, 2020 uzairadamjee 0 Comments

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)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK