Home » Python

Python File mode Property with Example

Python File mode Property: Here, we are going to learn about the mode Property, how to get the file mode from file object in Python?
Submitted by IncludeHelp, on December 24, 2019

File mode Property

mode Property is an inbuilt property of File object (IO object) in Python, it is used to get the mode (w, r, a, etc.) of the file from the file object in Python.




  • None

Return value:

The return type of this method is <class 'str'>, it returns the file mode.


# Python File mode Property with Example

# opening files in various modes
file1 = open("myfile1.txt", "w")
file2 = open("myfile3.txt", "a")
file3 = open("myfile4.txt", "wb")

# printing the file modes
print("file1 mode is:", file1.mode)
print("file2 mode is:", file2.mode)
print("file3 mode is:", file3.mode)

# closing the files


file1 mode is: w
file2 mode is: a
file3 mode is: wb

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.