from __future__ import with_statement from array import array x = array('i', [1,2,3,4,5]) with open("test.data", "wb") as f: x.tofile(f) x = array('i', []) with open("test.data", "r+b") as f: x.fromfile(f, 5) x *= 2 x.tofile(f) with open("test.data", "rb") as f: x.fromfile(f, 10) print x