在Python中获取字符串长度,然后将该int转换为字节数组的正确方法是什么?把它打印到控制台进行测试的正确方法是什么?
最佳答案
使用struct
import struct
print struct.pack('L', len("some string")) # int to a (long) byte array
在Python中获取字符串长度,然后将该int转换为字节数组的正确方法是什么?把它打印到控制台进行测试的正确方法是什么?
最佳答案
使用struct
import struct
print struct.pack('L', len("some string")) # int to a (long) byte array