我有一个PHP语句,用于将hex
字符串转换为binary
。
$m=pack("H*" , "A88BE9L98990........");
我需要在另一个 Python
程序中做同样的事情?
有什么想法吗?
谢谢!
binascii
模块拥有 binascii.unhexlify(hexstr)
方法,可以实现您想要的功能。>>> import binascii
>>> binascii.unhexlify("A88BE9L98990")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Non-hexadecimal digit found
# Not sure why there's an L in there... take it out...
>>> binascii.unhexlify("A88BE9989900")
'\xa8\x8b\xe9\x98\x99\x00'
python2php 网站可以帮助您 - 它建议使用 struct.pack
L
在那里有什么作用? - Tim Pietzcker