The Perl format "nNcc" equivalent to the Python format "!HLbb" . In Python there is no direct equivalent for Perl "H*" .
There are two problems.
- Python
struct.unpack does not accept wildcard, * - Python
struct.unpack does not perform "hexlify" data rows
The first problem can be solved with an auxiliary function like unpack .
The second problem can be solved with binascii.hexlify :
import struct import binascii def unpack(fmt, data): """ Return struct.unpack(fmt, data) with the optional single * in fmt replaced with the appropriate number, given the length of data. """
When testing the data received by this Perl script:
$line = pack("nNccH*", 1, 2, 10, 4, '1fba'); print "$line";
Python script gives
[1, 2, 10, 4, '1fba']
source share