open('utf data''rb'read( decode('aabecutf- is default decoding mismatches finallykeep in mind that this behavior of files in limits the kind of content you can load as text as suggested in the prior sectionpython really must be able to decode the data in text files into str stringaccording to either the default or passedin unicode encoding name trying to open truly binary data file in text modefor exampleis unlikely to work in even if you use the correct object typesfile open( ' :\python \python exe'' 'text file read(unicodedecodeerror'charmapcodec can' decode byte in position file open( ' :\python \python exe''rb'data file read(data[: 'mz\ \ \ \ \ \ \ \ \ \ \xff\xff\ \ \xb \ \ \ the first of these examples might not fail in python (normal files do not decode text)even though it probably shouldreading the file may return corrupted data in the stringdue to automatic end-of-line translations in text mode (any embedded \ \ bytes will be translated to \ on windows when readto treat file content as unicode text in xwe need to use special tools instead of the general open built-in functionas we'll see in moment firstthoughlet' turn to more explosive topic handling the bom in as described earlier in this some encoding schemes store special byte order marker (bomsequence at the start of filesto specify data endianness (which end of string of bits is most significant to its valueor declare the encoding type python both skips this marker on input and writes it on output if the encoding name implies itbut we sometimes must use specific encoding name to force bom processing explicitly for examplein the utf- and utf- encodingsthe bom specifies bigor littleendian format utf- text file may also include bombut this isn' guaranteedand serves only to declare that it is utf- in general when reading and writing data using these encoding schemespython automatically skips or writes the bom if it is either implied by general encoding nameor if you provide more specific encoding name to force the issue for instancein utf- the bom is always processed for "utf- ,and the more specific encoding name "utf- -ledenotes little-endian format in utf- the more specific encoding "utf- -sigforces python to both skip and write bom on input and outputrespectivelybut the general "utf- does not using unicode files