manual encoding as we've already learnedwe can always encode such string to raw bytes according to the target encoding nameencode manually with methods encode('latin- ' ' \xc \xe clen( encode('utf- ' ' \xc \ \xc \xa clen( bytes when encoded as latin- bytes when encoded as utf- file output encoding nowto write our string to text file in particular encodingwe can simply pass the desired encoding name to open--although we could manually encode first and write in binary modethere' no need toencoding automatically when written open('latindata'' 'encoding='latin- 'write( open('utf data'' 'encoding='utf- 'write( write as latin- write as utf- open('latindata''rb'read( ' \xc \xe cread raw bytes open('utf data''rb'read( ' \xc \ \xc \xa cdifferent in files file input decoding similarlyto read arbitrary unicode datawe simply pass in the file' encoding type name to openand it decodes from raw bytes to strings automaticallywe could read raw bytes and decode manually toobut that can be tricky when reading in blocks (we might read an incomplete character)and it isn' necessarydecoding automatically when read open('latindata'' 'encoding='latin- 'read('aabecopen('utf data'' 'encoding='utf- 'read('aabecx open('latindata''rb'read( decode('latin- ' unicode and byte strings decoded on input per encoding type manual decodingnot necessary