【问题标题】:Text to Zip to base64 and vice versa, in Python文本到 Zip 到 base64,反之亦然,在 Python 中
【发布时间】:2016-10-19 11:14:56
【问题描述】:

我有一个“文本”,它先转换为 zip,然后再转换为 base64。如果我有那个 base64 值,我如何将它转换回 python 中的纯文本。 ?

【问题讨论】:

  • 解码成二进制,然后解压

标签: python zip base64 zlib


【解决方案1】:

您使用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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    • 2012-02-16
    • 2013-08-16
    • 2012-06-27
    相关资源
    最近更新 更多