【发布时间】:2017-08-25 09:42:32
【问题描述】:
我尝试将 ascii 转换为十六进制值。但我的脚本有时工作,有时不工作。我想知道为什么。代码如下:
ascii_ch = B13515068
for i in range(50): #In excel I have 50 row
ascii_ch = sheet['C%s'%(i+2)].value #after C2, convert hex
ascii_to_hex= "".join("{:02x}".format(ord(c)) for c in ascii_ch )
sheet['I%s'%(i+2)] = ascii_to_hex
wb.save('a.xlsx')
我要 ascii_to_hex=423133353135303638
【问题讨论】:
-
阅读错误信息?
-
我在行尾分享了错误信息; ascii_to_hex= "".join("{:02x}".format(ord(c)) for c in ascii_ch ) TypeError: 'NoneType' object is not iterable
-
嗯,是的,我知道。但看起来你没看过。
-
有趣的是代码有时有效,有时却报错。
-
那一点也不有趣。
标签: python string python-3.x hex ascii