Python中对两种utf-8格式的理解

1、python文件开头utf-8格式的理解 
2、程序中读取文件时utf-8格式的理解


aa.py文件代码示例:

#!/usr/bin/python
# -*- coding:utf-8 -*-

fr1 = open("goods_information", "r", encoding="utf-8")
print(fr1.read())

其中# -- coding:utf-8 --代表Python解释器对本文件的解码格式,fr1 = open(“goods_information”, “r”, encoding=”utf-8”)中的utf-8代表读取文件进行解析时的解码格式,我感觉最后都指定一下。 
即: 
第二行代码中的utf-8代表对本文件aa.py的解码格式,第4行中的utf-8代表对读取文件goods_information的解码格式。

原文地址:https://www.cnblogs.com/hedianzhan/p/9644630.html