我正在尝试将列表映射到十六进制,然后在其他地方使用列表.在python 2.6中,这很简单:
答: Python 2.6:
>>> map(chr, [66, 53, 0, 94])
['B', '5', '\x00', '^']
Run Code Online (Sandbox Code Playgroud)
但是,在Python 3.1中,上面返回了一个map对象.
B: Python 3.1:
>>> map(chr, [66, 53, 0, 94])
<map object at 0x00AF5570>
Run Code Online (Sandbox Code Playgroud)
如何在Python 3.x上检索映射列表(如上面的A中所示)?
或者,有更好的方法吗?我的初始列表对象有大约45个项目,id喜欢将它们转换为十六进制.
我目前正在运行这个作为我的代码的i/o流 - 我得到以下错误TypeError:'map'对象不能打印print(bytest [:10]).在Python 3中运行它的正确方法是什么?
with open("/bin/ls", "rb") as fin: #rb as text file and location
buf = fin.read()
bytes = map(ord, buf)
print (bytes[:10])
saveFile = open('exampleFile.txt', 'w')
saveFile.write(bytes)
saveFile.close()
Run Code Online (Sandbox Code Playgroud)