【发布时间】:2012-12-14 06:28:53
【问题描述】:
def bintohex(path):
hexvalue = []
file = open(path,'rb')
while True:
buffhex = pkmfile.read(16)
bufflen = len(buffhex)
if bufflen == 0: break
for i in range(bufflen):
hexvalue.append("%02X" % (ord(buffhex[i])))
我正在制作一个函数,它将返回特定文件的十六进制值列表。但是,此函数在 Python 3.3 中无法正常工作。我应该如何修改这段代码?
File "D:\pkmfile_web\pkmtohex.py", line 12, in bintohex hexvalue.append("%02X" % (ord(buffhex[i]))) TypeError: ord() expected string of length 1, but int found
【问题讨论】:
-
定义“不能正常工作”
-
文件 "D:\pkmfile_web\pkmtohex.py",第 12 行,bintohex hexvalue.append("%02X" % (ord(buffhex[i]))) TypeError: ord() expected长度为 1 的字符串,但找到了 int
-
将该信息添加到问题本身。
标签: python python-3.x binary hex