我有一个很长的字符串,我想将它呈现为一个长数字。 我试过:
l=[ord (i)for i in str1]
但这不是我需要的。 我需要把它变成长数字而不是数字作为列表中的项目。 这一行给我 [23,21,45,34,242,32] 我想让它成为一个长数字,我可以将它再次更改为相同的字符串。
有什么想法吗?
请您参考如下方法:
这是将 Paulo Bu 的答案(使用 base64 编码)翻译成 Python 3:
>>> import base64
>>> s = 'abcde'
>>> e = base64.b64encode(s.encode('utf-8'))
>>> print(e)
b'YWJjZGU='
>>> base64.b64decode(e).decode('utf-8')
'abcde'
基本上不同之处在于您的工作流程已经从:
string -> base64
base64 -> string
收件人:
string -> bytes
bytes -> base64
base64 -> bytes
bytes -> string
