number '\ \ struct unpack('> 'number( ,packed binary data crops up in many contextsincluding some networking tasksand in data produced by other programming languages because it' not part of every programming job' descriptionthoughwe'll defer to the struct module' entry in the python library manual for more details random access files binary files also typically see action in random access processing earlierwe mentioned that adding to the open mode string allows file to be both read and written this mode is typically used in conjunction with the file object' seek method to support random read/write access such flexible file processing modes allow us to read bytes from one locationwrite to anotherand so on when scripts combine this with binary file modesthey may fetch and update arbitrary bytes within file we used seek earlier to rewind files instead of closing and reopening as mentionedread and write operations always take place at the current position in the filefiles normally start at offset when opened and advance as data is transferred the seek call lets us move to new position for the next transfer operation by passing in byte offset python' seek method also accepts an optional second argument that has one of three values-- for absolute file positioning (the default) to seek relative to the current positionand to seek relative to the file' end that' why passing just an offset of to seek is roughly file rewind operationit repositions the file to its absolute start in generalseek supports random access on byte-offset basis seeking to multiple of record' size in binary filefor instanceallows us to fetch record by its relative position although you can use seek without modes in open ( to just read from random locations)it' most flexible when combined with input/output files and while you can perform random access in text modetoothe fact that text modes perform unicode encodings and line-end translations make them difficult to use when absolute byte offsets and lengths are required for seeks and reads--your data may look very different when stored in files text mode may also make your data nonportable to platforms with different default encodingsunless you're willing to always specify an explicit encoding for opens except for simple unencoded ascii text without line-endsseek tends to works best with binary mode files to demonstratelet' create file in + mode (equivalent to wb+and write some data to itthis mode allows us to both read and writebut initializes the file to be empty if it' already present (all modes doafter writing some datawe seek back to file start to read its content (some integer return values are omitted in this example again for brevity)file tools