Advertisement
jabela

File access

Aug 26th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import struct
  2.  
  3. thefile = open('somebinfile', 'r+b')
  4. record_size = struct.calcsize(format_string)
  5.  
  6. thefile.seek(record_size * record_number)
  7. buffer = thefile.read(record_size)
  8. fields = list(struct.unpack(format_string, buffer))
  9.  
  10. # Perform computations, suitably modifying fields, then:
  11.  
  12. buffer = struct.pack(format_string, *fields)
  13. thefile.seek(record_size * record_number)
  14. thefile.write(buffer)
  15.  
  16. thefile.close(  )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement