writing and reading binary data writing and parsing text files writing and parsing xml files random access binary files |||file handling most programs need to save and load informationsuch as data or state informationto and from files python provides many different ways of doing this we already briefly discussed handling text files in and pickles in the preceding in this we will cover file handling in much more depth all the techniques presented in this are platform-independent this means that file saved using one of the example programs on one operating system/processor architecture combination can be loaded by the same program on machine with different operating system/processor architecture combination and this can be true of your programs too if you use the same techniques as the example programs the first three sections cover the common case of saving and loading an entire data collection to and from disk the first section shows how to do this using binary file formatswith one subsection using (optionally compressedpicklesand the other subsection showing how to do the work manually the second section shows how to handle text files writing text is easybut reading it back can be tricky if we need to handle nontextual data such as numbers and dates we show two approaches to parsing textdoing it manually and using regular expressions the third section shows how to read and write xml files this section covers writing and parsing using element treeswriting and parsing using the dom (document object model)and writing manually and parsing using sax (simple api for xmlthe fourth section shows how to handle random access binary files this is useful when each data item is the same size and where we have more items than we want in (or can fit intomemory which is the best file format to use for holding entire collections--binarytextor xmlwhich is the best way to handle each formatthese questions are too context-dependent to have single definitive answerespecially since there are