2012-12-15 92 views
1

我在php下面有這樣的說法將hex的字符串轉換爲binaryPython的等價物的php包

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

我需要在另一個python程序中做同樣的事情嗎?

任何想法?

乾杯,

+3

什麼的'L'做什麼呢? –

回答

5

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' 
+0

非常感謝你!原始字符串太大而無法發佈。所以我只是隨機打字。 –

0

python2php網站可以幫助你 - 它建議使用struct.pack

+2

struct.pack完成大部分PHP包的功能,但它不處理十六進制轉換。 –