简体   繁体   中英

Python equivalent of php pack

I have this statement below in php to convert hex string to binary .

$m=pack("H*" , "A88BE9L98990........");

I need to do the same in another python program ?

Any Ideas ?

Cheers,

The binascii module has binascii.unhexlify(hexstr) , which does what you want.

>>> 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM