[英]Decode base64 encoded file and print results to the console
因此,我有一个已经用base64编码的文件,现在我想将其解码回去,但是我不想在控制台中对其进行解码,而是将结果打印到屏幕上,而不是创建另一个文件。 怎么做?
编码的文件字符串= MUhRRy1ITVRELU0zWDItNlcxSA==
仅供参考:这意味着先在控制台中打开文件,然后解码给定字符串
谢谢
除非我忽略了某些内容,否则这就像读取您的编码字符串然后在其上调用标准库的base64.b64decode
函数一样简单。
就像是:
with open(path_to_encoded_file) as encoded_file:
print base64.b64decode(encoded_file.read().strip())
使用base64.decode ,将sys.stdout
(在python 3.x中为sys.stdout.buffer.raw
)设置为输出。
import sys
import base64
with open('filepath') as f:
base64.decode(f, sys.stdout)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.