Hello there, I have a 22 GB binary file, a want to change values of specific positions. Because of the volume of the file, I doubt my code a efficient one:
#! /usr/bin/env python #coding=utf-8 import sys import struct try: f=open(sys.argv[1],'rb+') except (IOError,Exception): print '''usage: scriptname segyfilename ''' sys.exit(1) #skip EBCDIC header try: f.seek(3200) except Exception: print 'Oops! your file is broken..' #read binary header binhead = f.read(400) ns = struct.unpack('>h',binhead[20:22])[0] if ns < 0: print 'file read error' sys.exit(1) #read trace header while True: f.seek(28,1) f.write(struct.pack('>h',1)) f.seek(212,1) f.seek(ns*4,1) f.close() -- http://mail.python.org/mailman/listinfo/python-list