相当于php pack的Python

发布于 2021-01-29 15:05:37

我在php中将以下语句转换hexbinary

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

我需要在另一个python程序中做同样的事情吗?

有任何想法吗 ?

干杯,

关注者
0
被浏览
132
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    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'
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看