pythonbase64

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


Solution

  • 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())