简体   繁体   English

如何解压Python中的字符串?

[英]How to decompress a string in Python?

I am trying to decompress a string that is Gzipped.我正在尝试解压缩 Gzipped 的字符串。 But I am unable to do so.但我无法这样做。

string = 'H4sIAAAAAAAAClWPwcrCQAyEX2WOCtJ3+EXw5E3wvLZjG4gb2WR/tU/vFlEQQiATvszkRO3tSoThUDWkhmiH4ySOVjEtG1PcJxbiaRV9ymjErdB9EQqCj4AVDPzVPxMH/CetRHXJI/az3FbjvN5gx0vS4MJui4XKFxHLSDpakZiu3uFP3X7cU0uzhHOZiTPjTua3q7fWEykPaJfaS5CM8zPo3QvUlCS87AAAAA=='
x = gzip.decompress(string).decode()

But this throws an error.但这会引发错误。 But the string should be decompressed to "Welcome to Multiutil. This is the tool where you can compress your text or decompress your compressed value using Gzip(gz), Defalte or Brotli compression algorithms. Also you can compare the size between your source and result in bytes."但是字符串应该被解压缩为“欢迎使用 Multiutil。这是您可以使用 Gzip(gz)、Defalte 或 Brotli 压缩算法压缩文本或解压缩压缩值的工具。您还可以比较源和结果之间的大小以字节为单位。” Is there a way to decompress the string in Python?有没有办法解压Python中的字符串?

First decode the base64 encoded string.首先解码 base64 编码的字符串。

import base64
import gzip

binary_string = base64.b64decode(string)
x = gzip.decompress(binary_string).decode()

Welcome to Multiutil. This is the tool where you can compress your text or decompress your compressed value using Gzip(gz), Defalte or Brotli compression algorithms. Also you can compare the size between your source and result in bytes.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM