working with struct



In [ ]:
# Notes for working with struct
Working with binary data, this cn be used for hacking and stuff

Convert between strings and binary/octal/hex representation

Includes functions that convert strings of bytes and native python data types

ex: str_of_bytes = '\x94\x82\xff\x3a' We want to convert this string of bytes in a python data type to manipulate


In [1]:
import struct
import binascii

In [2]:
values = (1, 'ab', 2.7)

In [4]:
s = struct.Struct('I 2s f')
dir(s)


Out[4]:
['__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'format',
 'iter_unpack',
 'pack',
 'pack_into',
 'size',
 'unpack',
 'unpack_from']

In [ ]: