Tags
python
Asked 2 years ago
12 Aug 2021
Views 234
Amina

Amina posted

How do I read a file in Python 3 ?

How do I read a file in Python 3 ?
fatso

fatso
answered Jan 21 '22 00:00

read()

read() is a python function gets used to reading the content from the file.



fileobject = open("data.csv", "r")
print(fileobject.read())


fileobject.readline() will read entire contents from the csv

if you want to read the part of the line then you need to pass the number of bytes.


fileobject = open("data.csv", "r")
print(fileobject.read(10))



read(10) is used to read 10 bytes from the file.


readline()

readline() is python function get used to read the line from the file .

fileobject = open("data.csv", "r")
print(fileobject.readline())

fileobject.readline() will read first line from the csv

if you want to read the part of the line then you need to pass the number of bytes .

fileobject = open("data.csv", "r")
print(fileobject.readline(10))


readline(10) is used to read 10 bytes from the first line.


Post Answer