簡體   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