在Python 3.7字节中,对象没有 encode() 方法下面的代码不再有效。
encode()
import struct hex_str = struct.pack('2I',12, 30).encode('hex')
而不是 编码() ,Python 3.7代码应使用 hex() 方法,在Python 3.5中介绍。
编码()
hex()
import struct # hex_str will contain the '0c0000001e000000' string. hex_str = struct.pack('2I',12, 30).hex()