Python equivalent of php pack

前端 未结 2 464
庸人自扰
庸人自扰 2020-12-21 09:49

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

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

I

2条回答
  •  执笔经年
    2020-12-21 10:17

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

    >>> import binascii
    >>> binascii.unhexlify("A88BE9L98990")
    Traceback (most recent call last):
      File "", line 1, in 
    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'
    

提交回复
热议问题