gpt4 book ai didi

python - 获取填充字典的大小

转载 作者:行者123 更新时间:2023-11-28 17:49:15 24 4
gpt4 key购买 nike

我想在 python 中获取填充字典的大小。我试过这个:

>>> dict = {'1':1}
>>> import sys
>>> print dict
{'1': 1}
>>> sys.getsizeof(dict)
140

但这显然行不通。我期望的返回值是 2(字节)。我会有一本字典,内容如下:

{'L\xa3\x93': '\x15\x015\x02\x00\x00\x00\x01\x02\x02\x04\x1f\x01=\x00\x9d\x00^\x00e\x04\x00\x0b', '\\\xe7\xe6': '\x15\x01=\x02\x00\x00\x00\x01\x02\x02\x04\x1f\x01B\x00\xa1\x00_\x00c\x04\x02\x17', '\\\xe8"': '\x15\xff\x1d\x02\x00\x00\x00\x01\x02\x02\x04\x1f\x01:\x00\x98\x00Z\x00_\x04\x02\x0b', '\\\xe6@': '\x15\x014\x02\x00\x00\x00\x01\x02\x02\x04\x1f\x01@\x00\x9c\x00\\\x00b\x04\x00\x0b'}

我想知道我需要发送多少字节的数据。我的索引是 6 字节,但内容有多长?我知道每个索引是 46 字节,所以我想知道我需要传输 4*(6+46) 字节....我该怎么做最好?

谢谢,罗恩

最佳答案

那么,当我需要一个字节一个字节地传输内容时,只有这个才能给我真正的长度吗?

#non_mem_macs is my dictionary
for idx in non_mem_macs:
non_mem_macs_len += len(hexlify(idx))
non_mem_macs_len += len(hexlify(non_mem_macs[idx]))

关于python - 获取填充字典的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13316113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com