python随机生成汉字并查看编码方式

来源:互联网 发布:什么是多媒体集成软件 编辑:程序博客网 时间:2024/06/05 14:13
# -*- coding: utf-8 -*-
import random
import chardet

"""用于随机生成汉字"""

status = 0
for i in range(1, 15):
    str2 = ""
    try:
        for j in range(0, 83):
            head = random.randint(0xB0, 0xCF)
            body = random.randint(0xA, 0xF)
            tail = random.randint(0, 0xF)
            val = (head << 8) | (body << 4) | tail
            str1 = "%x" % val
            str2 += str1.decode('hex').decode('gb2312').encode("utf-8")
            print str2
    except:
        status = 1

    print "status :   " + str(status)
    if status == 0:
        break
print chardet.detect(str2)
0 0
原创粉丝点击