简体   繁体   中英

Decode base64 encoded file and print results to the console

So I have a file that I have already encoded with base64, now I want to decode it back but instead of creating another file, I want to decode it in the console and print the results to screen. How to do that?

encoded file string = MUhRRy1ITVRELU0zWDItNlcxSA==

FYI: this would mean first opening the file in console, then decoding the give string

Thanks

Unless I'm overlooking something, this is as simple as reading in your encoded string and then calling the standard library's base64.b64decode function on it.

Something like:

with open(path_to_encoded_file) as encoded_file:
    print base64.b64decode(encoded_file.read().strip())

Using base64.decode , set sys.stdout ( sys.stdout.buffer.raw in python 3.x) as output.

import sys
import base64

with open('filepath') as f:
    base64.decode(f, sys.stdout)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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