Python provides open()
to open a file and open() returns a built-in type file object. The
default mode is read.
fread = open("1.txt") is
equivalent to fread = open("1.txt", "r"), where fread is
where the file object returned by open() is stored.
Python provides read(), readline()
and readlines() functions to read a file. read() reads entire
file at once. readline() reads next line from the open file. readlines()
returns a list where each element is a line of a file.
The file can also be open in write
mode. Python provides write() to write a string in a file, writelines() to
write a sequence of lines at once.
The built-in type file object has close()
to which is called for all open files
No comments:
Post a Comment