【发布时间】:2016-10-19 11:14:56
【问题描述】:
我有一个“文本”,它先转换为 zip,然后再转换为 base64。如果我有那个 base64 值,我如何将它转换回 python 中的纯文本。 ?
【问题讨论】:
-
解码成二进制,然后解压
我有一个“文本”,它先转换为 zip,然后再转换为 base64。如果我有那个 base64 值,我如何将它转换回 python 中的纯文本。 ?
【问题讨论】:
您使用base64 module 将base 64 转换回来,然后使用zipfile module 转换zip。
假设file.txt 被压缩成file.zip,然后存档被转换为base 64 为encoded.txt:
import zipfile
import base64
base64.decode(open('encoded.txt'), open('file.zip', 'w'))
ZipFile('file.zip').extractall()
plaintext = open('file.txt').read()
【讨论】: