python 示例_带有示例的Python文件编码属性
python 示例
文件编码属性 (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”.
encoding属性是Python中File对象(IO对象)的内置属性,用于从文件对象获取文件的编码格式。 默认编码格式为“ utf-8” ,代表“ Unicode转换格式8位” 。
Syntax:
句法:
file_object.encoding
Parameter(s):
参数:
None
没有
Return value:
返回值:
The return type of this method is
此方法的返回类型为
Example:
例:
# 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.close()
file2.close()
file3.close()
Output
输出量
file1 encoding format is: UTF-8
file2 encoding format is: UTF-8
file3 encoding format is: utf-16
翻译自: https://www.includehelp.com/python/file-encoding-property-with-example.aspx
python 示例
还没有评论,来说两句吧...