Python编码

来源:互联网 发布:阿里云 dnspod 编辑:程序博客网 时间:2024/06/03 18:09
# -*- coding:UTF-8 -*-def read_code():    # 字符串在Python内部的表示是Unicode编码,因此,在编码转换时,通常需要以Unicode作为中间编码,    # 先将其他编码的字符串解码(decode)成Unicode,再从Unicode编码(encode)成另一种编码。    # decode的作用:将其他编码转换成Unicode编码    str.decode('gb2312')  # 将gb2312编码的字符串str转换为Unicode编码    # encode的作用:将Unicode编码转换成其他编码    str.encode('gb2312')  # 将Unicode编码的字符串str转换为gb2312编码if __name__ == "__main__":    read_code()
0 0
原创粉丝点击