[code.view]

[top] / python / PyMOTW / struct / struct_pack.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """
     """
     
     __version__ = "$Id$"
     #end_pymotw_header
     
     import struct
     import binascii
     
     values = (1, 'ab', 2.7)
     s = struct.Struct('I 2s f')
     packed_data = s.pack(*values)
     
     print 'Original values:', values
     print 'Format string  :', s.format
     print 'Uses           :', s.size, 'bytes'
     print 'Packed Value   :', binascii.hexlify(packed_data)
     

[top] / python / PyMOTW / struct / struct_pack.py

contact | logmethods.com