Python equivalent of php pack

前端 未结 2 463
庸人自扰
庸人自扰 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 09:59

    python2php web site can help you - it suggest using struct.pack

    0 讨论(0)
  • 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 "<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'
    
    0 讨论(0)
提交回复
热议问题