Find the mode of the opened file in python by R4R Team

-In file handling, we operate many files in the program and make multiple file objects in different modes.
-for identifing that file was opened in which mode, then we use 'mode' attribute.

Syntax-

fileobject.mode


program-

f=open('myfile.txt','w')
print(f.mode)
f.close()

f=open('myfile.txt','r')
print(f.mode)
f.close()

f=open('myfile.txt','a')
print(f.mode)
f.close()

f=open('myfile.txt','rt')
print(f.mode)
f.close()


output-

w
r
a
rt


-In this program, we open the different files in different modes and make file object for each file, then using fileobject.mode we will print the mode of the file.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!