example
Counts number of lines and print them.
f=open("D:/test.txt","r")
for x in f:
print (x)
_______
output:
hello everyone, welcome to python programming classes
this is a appending operation in file
access modes:read
r-read: only reading
file must exsits before opening file
file pointer points at the begining of the file.
write mode
w-writing contents into the file
file exists-begining of file and over writtens the data
not exists-new files is created
append()
file exists :pointer points at the end of the content.
new file is created
writing to the file
write()- single line
writelines()-multi line
example:
#reading file and display the contents
f=open("D:/test.txt","r")
print(f.read())
_____________
output:
hello everyone, welcome to python programming classes
example:
f=open("D:/test.txt","w")
print(f.write("this is a appending operation in file"))
--------------
output:
37
contin
f=open("D:/test.txt","r")
for x in f:
print (x)
--------------------
output:
this is a appending operation in file
delete()
first close the opened file.
f.close()
import library os
syntax:
os.remove(“path of file”)