distinction when using system tools like pipe descriptors and socketsbecause they transfer data as byte strings today (though their content can be decoded and encoded as unicode text if neededmoreoverbecause text-mode files require that content be decodable per unicode encoding schemeyou must read undecodable file content in binary modeas byte strings (or catch unicode exceptions in try statements and skip the file altogetherthis may include both truly binary files as well as text files that use encodings that are nondefault and unknown as we'll see later in this because str strings are always unicode in xit' sometimes also necessary to select byte string mode for the names of files in directory tools such as os listdirglob globand os walk if they cannot be decoded (passing in byte strings essentially suppresses decodingin factwe'll see examples where the python distinction between str text and bytes binary pops up in tools beyond basic files throughout this book--in and when we explore socketsin and when we'll need to ignore unicode errors in file and directory searchesin where we'll see how clientside internet protocol modules such as ftp and emailwhich run atop socketsimply file modes and encoding requirementsand more but just as for string typesalthough we will see some of these concepts in action in this we're going to take much of this story as given here file and string objects are core language material and are prerequisite to this text as mentioned earlierbecause they are addressed by -page in the book learning pythonfourth editioni won' repeat their coverage in full in this book if you find yourself confused by the unicode and binary file and string concepts in the following sectionsi encourage you to refer to that text or other resources for more background information in this domain using built-in file objects despite the text/binary dichotomy in python xfiles are still very straightforward to use for most purposesin factthe open built-in function and its files objects are all you need to remember to process files in your scripts the file object returned by open has methods for reading data (readreadlinereadlines)writing data (writewritelines)freeing system resources (close)moving to arbitrary positions in the file (seek)forcing data in output buffers to be transferred to disk (flush)fetching the underlying file handle (fileno)and more since the built-in file object is so easy to uselet' jump right into few interactive examples output files to make new filecall open with two argumentsthe external name of the file to be created and mode string (short for writeto store data on the filecall the file object' write method with string containing the data to storeand then call the close method file tools