Base64在Python中将文本文件解码为Bin文件

Base64在Python中将文本文件解码为Bin文件,python,python-3.x,binary,base64,decode,Python,Python 3.x,Binary,Base64,Decode,我有一个文本文件,我想把它解码成二进制代码文件 目前,我正在Windows上使用openssl来实现这一点。 命令是:base64-d input.txt output.bin 对于这个问题,Python的base64命令可以是什么 编辑: input.txt内容: India USA Africa Europe 我的尝试: InputFile = open('input.txt', 'r') InputFile_Content = InputFile.read() print(InputFi

我有一个文本文件,我想把它解码成二进制代码文件

目前,我正在Windows上使用
openssl
来实现这一点。 命令是:
base64-d input.txt output.bin

对于这个问题,Python的
base64
命令可以是什么

编辑:

input.txt
内容:

India
USA
Africa
Europe
我的尝试:

InputFile = open('input.txt', 'r')
InputFile_Content = InputFile.read()
print(InputFile_Content)

print(base64.decode(InputFile_Content, 'Output.bin'))

错误:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    print(base64.decode(InputFile_Content, 'Output.bin'))
  File "Python\Python37\lib\base64.py", line 502, in decode
    line = input.readline()
AttributeError: 'str' object has no attribute 'readline'
回溯(最近一次呼叫最后一次):
文件“test.py”,第9行,在
打印(base64.decode(输入文件内容'Output.bin'))
文件“Python\Python37\lib\base64.py”,第502行,解码
line=input.readline()
AttributeError:“str”对象没有属性“readline”

一篇关于编码和解码base64字符串的快速谷歌搜索文章。在python中实现这一点的一个好方法可能是:

导入base64
以open(“input.txt”、“r”)作为f:
message=f.read().encode(“ascii”)
以open(“output.bin”、“wb”)作为f:
f、 写入(base64.b64编码(消息))

然后你应该在提问前做一些研究,张贴你尝试过的代码和错误,你也可以使用该模块或.Added@komatiraju032。看到你的编辑后,我想我的答案仍然是你想要的。我将研究如何使用Python中的open正确打开和编辑文件。如果我的答案有帮助,请将其标记为正确答案!当然,我会的。我正在我的代码上测试它。一旦我得到了预期的结果,我将标记你的答案。