繁体   English   中英

相当于php pack的Python

[英]Python equivalent of php pack

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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