Home » Python

Python File encoding Property with Example

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

File encoding Property

encoding Property is an inbuilt property of File object (IO object) in Python, it is used to get the file's encoding format from the file object. The default encoding format is "utf-8" which stands for "Unicode Transformation Format 8 bits".




  • None

Return value:

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


# Python File encoding Property with Example

# opening files in various modes
file1 = open("myfile1.txt", "w")
file2 = open("myfile3.txt", "a")
file3 = open("myfile4.txt", "w", encoding='utf-16')

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

# closing the files


file1 encoding format is: UTF-8
file2 encoding format is: UTF-8
file3 encoding format is: utf-16

Comments and Discussions

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.