【发布时间】:2020-06-08 12:23:58
【问题描述】:
import base64
s = "05052020"
python2.7
base64.b64encode(s)
输出是字符串'MDUwNTIwMjA='
python 3.7
base64.b64encode(b"05052020")
输出是字节
b'MDUwNTIwMjA='
我想用“a”替换=
s = str(base64.b64encode(b"05052020"))[2:-1]
s = s.replace("=", "a")
我意识到这是肮脏的方式,所以我怎样才能做得更好?
编辑: 预期结果:
带有替换填充的 Python 代码 3 输出字符串
【问题讨论】:
-
预期结果是什么(字符串或字节)?你想要代码兼容 Python2 和 Python 3 吗?
-
Python3 中的代码和输出应为替换填充的字符串。