如何检查压缩字符串由多少字节组成?
How to check how many bytes a compressed string consist of?
我使用 python 3 使用 zlib 压缩了两个字符串,如下所示:
t1 = "Hi my name is David"
t2 = t1* 10
t1Compressed = zlib.compress(t1.encode())
t10Compressed = zlib.compress(t10.encode())
现在我想计算一下 t1Compressed 和 t10Compressed 有多少字节。我该怎么做?
谢谢!
len(t1Compressed)
给出字节的长度。
如果您想在 Python 中查找某些内容的长度,请尝试 len
。
类型是bytes
所以只用len()
方法
>>> t1 = "Hi my name is David"
>>> t2 = t1* 10
>>> t1Compressed = zlib.compress(t1.encode())
>>> t10Compressed = zlib.compress(t2.encode())
>>> type(t1Compressed)
<class 'bytes'>
>>> len(t1Compressed)
27
>>> len(t10Compressed)
30
我使用 python 3 使用 zlib 压缩了两个字符串,如下所示:
t1 = "Hi my name is David"
t2 = t1* 10
t1Compressed = zlib.compress(t1.encode())
t10Compressed = zlib.compress(t10.encode())
现在我想计算一下 t1Compressed 和 t10Compressed 有多少字节。我该怎么做?
谢谢!
len(t1Compressed)
给出字节的长度。
如果您想在 Python 中查找某些内容的长度,请尝试 len
。
类型是bytes
所以只用len()
方法
>>> t1 = "Hi my name is David"
>>> t2 = t1* 10
>>> t1Compressed = zlib.compress(t1.encode())
>>> t10Compressed = zlib.compress(t2.encode())
>>> type(t1Compressed)
<class 'bytes'>
>>> len(t1Compressed)
27
>>> len(t10Compressed)
30