[英]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.