input and output in this casedata read from the file will be interpreted according to the encoding supplied in inputenc data written to the file will be interpreted according to the encoding in inputenc and written according to the encoding in outputenc if outputenc is omittedit defaults to the same as inputenc errors has the same meaning as described earlier when putting an encodedfile wrapper around an existing filemake sure that file is in binary mode otherwisenewline translation might break the encoding when you're working with unicode filesthe data encoding is often embedded in the file itself for examplexml parsers may look at the first few bytes of the string 'to determine the document encoding if the first four values are ('<?xm')the encoding is assumed to be utf- if the first four values are or the encoding is assumed to be utf- big endian or utf- little endianrespectively alternativelya document encoding may appear in mime headers or as an attribute of other document elements here' an examplesimilarlyunicode files may also include special byte-order markers (bomthat indicate properties of the character encoding the unicode character +feff is reserved for this purpose typicallythe marker is written as the first character in the file programs then read this character and look at the arrangement of the bytes to determine encoding (for example'\xff\xfefor utf- -le or '\xfe\xffutf- -beonce the encoding is determinedthe bom character is discarded and the remainder of the file is processed unfortunatelyall of this extra handling of the bom is not something that happens behind the scenes you often have to take care of this yourself if your application warrants it when the encoding is read from documentcode similar to the following can be used to turn the input file into an encoded streamf open("somefile","rb"determine encoding of the file put an appropriate encoding wrapper on the file assumes that the bom (if anyhas already been discarded by earlier statements fenc codecs encodedfile( ,encodingdata fenc read(unicode data encodings table lists some of the most commonly used encoders in the codecs module table encoders in the codecs module encoder description 'ascii'latin- ''iso- - 'cp 'cp 'utf- 'utf- ascii encoding latin- or iso- - encoding cp encoding cp encoding -bit variable-length encoding -bit variable-length encoding lib fl ff