import PrintHelper
print('首先我们将一个数组转换成bytes')
PrintHelper.PrintCode('bs=bytes(range(0,2**4))')
bs=bytes(range(0,2**4),)
print('输出它,你可以看到一批\\x开头的内容,这是MBCS码下的数字')
print('笔者在写这个用例时,系统的默认编码是MBCS码')
PrintHelper.PrintCode('print(bs)')
print(bs)
print('遍历输出bs的话,你看到的则都是对应存储的数值0-15')
PrintHelper.PrintCode('for i in bs:')
PrintHelper.PrintCode('    print(i,end=\" \")')
PrintHelper.PrintCode('    print(type(i))')
PrintHelper.PrintCode('print()')
for i in bs:
    print(i,end=" ")
    print(type(i))
print()
print(len(bs))
print('竟然不能用这种形式输出print(bs.decode(\"utf-8\"))')
print('查看系统编码sys.getdefaultencoding()')
PrintHelper.PrintCode('import sys')
import sys
PrintHelper.PrintCode('print(sys.getdefaultencoding())')
print(sys.getdefaultencoding())
print('笔者看到的是utf-8这就奇怪,字符集合是utf-8编码,可是utf-8解码缺不能看到正确的结果')
print('试试看解码一个上面输出的字符串')
PrintHelper.PrintCode('s=b\'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\'')
s=b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
PrintHelper.PrintCode('print(s.decode(\"utf-8\"))')
print(s.decode("utf-8"))
print('显示一样,那就对了 这不是一个正确的utf-8编码集合')
print('好吧,自己用utf-8编码一份字符串试试')
PrintHelper.PrintCode('s=\"人生苦短，我用Python\".encode(\"utf-8\")')
s="人生苦短，我用Python".encode("utf-8")
PrintHelper.PrintCode('print(s)')
print(s)
PrintHelper.PrintCode('print(s.decode(\"utf-8\"))')
print(s.decode("utf-8"))
