Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. from struct import unpack
  2.  
  3. class PHeader:
  4.     """Using a Python class as a C struct substitute"""
  5.     def __init__(self):
  6.         self.MagicNumber = ""
  7.         self.Version = ""
  8.         self.Comment = ""
  9.        
  10. if __name__ == '__main__':
  11.    
  12.     p = open('c:\\SDK\\file.p', 'r')
  13.     s = PHeader()
  14.    
  15.     s.MagicNumber = unpack('i', (p.read(4)))
  16.     s.Version = unpack('i', (p.read(4)))
  17.     s.Comment = unpack('128s', (p.read(128)))
  18.    
  19.     print('Magic Number: %s') % hex(s.MagicNumber[0])
  20.     print('Version: %d') % s.Version[0]
  21.     print('Comment: %s') % s.Comment[0]
  22.    
  23.     p.close()