【脚本语言系列】关于Python数据处理二进制数据,你需要知道的事
如何使用二进制数据
字节和字节数组
# -*- coding:utf-8 -*-
# only for Python3.*
blist =[12,23,34,45]
# variable
this_byte_array = bytearray(blist)
print this_byte_array
this_byte_array[1] = 127
print this_byte_array
# invariable
this_bytes = bytes(blist)
print this_bytes
this_bytes[1] = 127
print this_bytes
"-
"-
[12, 23, 34, 45]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-21-9bbd1152090e> in <module>()
11 this_bytes = bytes(blist)
12 print this_bytes
---> 13 this_bytes[1] = 127
14 print this_bytes
TypeError: 'str' object does not support item assignment