我有以下代码
import os
unk2 = os.urandom(10)
totlen = len("lol1") + len("lol2")
ownershipsectionwithsig = "random1" + "random2"
ticket = list(unk2) + list(ownershipsectionwithsig)
ticket = "".join(map(str, ticket))
print(ticket)
这段代码是为我测试的与RNG相关的东西编写的
在Python2中,它打印以下?zoռv3L??random1random2
但是在Python3中,它会打印 245148103178837822864207104random1random2
由于某种原因,Python3不像Python2那样显示原始字节输出,而是将其转换为某些内容。我将如何更改代码,使python 3以python 2的方式输出代码
提前谢谢
在Python 2中
bytes
是一个字符串序列,因此通过调用list(unk2)
将其转换为一个列表将其转换为单个字符串的列表:在Python 3中
bytes
是一个8位整数序列,因此通过调用list(unk2)
将其转换为一个整数列表,并将每个整数映射为一个字符串并将它们连接在一起,最终得到一个长的数字序列:如果要使Python 3像在Python 2中一样以字符串形式输出随机字节序列,可以使用
bytes
方法将bytes.decode
转换为字符串:相关问题 更多 >
编程相关推荐