file handling random access binary files ||in the earlier sections we worked on the basis that all of program' data was read into memory in one goprocessedand then all written out in one go modern computers have so much ram that this is perfectly viable approacheven for large data sets howeverin some situations holding the data on disk and just reading the bits we need and writing back changes might be better solution the disk-based random access approach is most easily done using key-value database ( "dbm")or full sql database--both are covered in --but in this section we will show how to handle random access files by hand we will first present the binaryrecordfile binaryrecordfile class instances of this class represent generic readable/writable binary filestructured as sequence of fixed length records we will then look at the bikestock bikestock class which holds collection of bikestock bike objects as records in binaryrecordfile binaryrecordfile to see how to make use of binary random access files generic binaryrecordfile class |the binaryrecordfile binaryrecordfile class' api is similar to list in that we can get/set/delete record at given index position when record is deletedit is simply marked "deleted"this saves having to move all the records that follow it up to fill the gapand also means that after deletion all the original index positions remain valid another benefit is that record can be undeleted simply by unmarking it the price we pay for this is that deleting records doesn' save any disk space we will solve this by providing methods to "compactthe fileeliminating deleted records (and invalidating index positionsbefore reviewing the implementationlet' look at some basic usagecontact struct struct("< si"contacts binaryrecordfile binaryrecordfile(filenamecontact sizehere we create struct (little-endian byte ordera -byte byte stringand -byte signed integerthat we will use to represent each record then we create binaryrecordfile binaryrecordfile instance with filename and with record size to match the struct we are using if the file exists it will be opened with its contents left intactotherwiseit will be created in either case it will be opened in binary read/write modeand once openwe can write data to itcontacts[ contact pack("abe bakerencode("utf ") contacts[ contact pack("cindy doveencode("utf ")