[英]python bz2 compression of string
>>> import bz2
>>> bz2.compress('hi')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ryan/anaconda/lib/python3.4/bz2.py", line 498, in compress
return comp.compress(data) + comp.flush()
TypeError: 'str' does not support the buffer interface
我看过使用字符串作为输入的示例,但对我来说不起作用
压缩算法压缩字节, 而不是text 。
3>> bz2.compress(b'hi')
b'BZh91AY&SY\x9a\x89\xb4"\x00\x00\x00\x01\x00\x00` \x00!\x00\x82\xb1w$S\x85\t\t\xa8\x9bB '
3>> bz2.compress('hi'.encode('utf-8'))
b'BZh91AY&SY\x9a\x89\xb4"\x00\x00\x00\x01\x00\x00` \x00!\x00\x82\xb1w$S\x85\t\t\xa8\x9bB '
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.