raw bytes do not correspond to utf- unicodedecodeerror'utf codec can' decode bytes in position - both these constraints make sense if you remember that byte strings hold bytes-based datanot decoded unicode code point ordinalswhile they may contain the encoded form of textdecoded code point values don' quite apply to byte strings unless the characters are first encoded converting encodings so farwe've been encoding and decoding strings to inspect their structure it' also possible to convert string to different encoding than its originalbut we must provide an explicit encoding name to encode to and decode from this is true whether the original text string originated in file or literal the term conversion may be misnomer here--it really just means encoding text string to raw bytes per different encoding scheme than the one it was decoded from as stressed earlierdecoded text in memory has no encoding typeand is simply string of unicode code points ( characters)there is no concept of changing its encoding in this form stillthis scheme allows scripts to read data in one encoding and store it in anotherto support multiple clients of the same datab ' \xc \ \xc \xa cs decode('utf- ' 'aabectext encoded in utf- format originally decode to unicode text per utf- encode('cp ' '\xc \xc \xc convert to encoded bytes per ebcdic decode('cp ' 'aabecconvert back to unicode per ebcdic encode( ' \xc \ \xc \xa cper default utf- encoding again keep in mind that the special unicode and hex character escapes are only necessary when you code non-ascii unicode strings manually in practiceyou'll often load such text from files instead as we'll see later in this ' file object (created with the open built-in functionautomatically decodes text strings as they are read and encodes them when they are writtenbecause of thisyour script can often deal with strings genericallywithout having to code special characters directly later in this we'll also see that it' possible to convert between encodings when transferring strings to and from filesusing technique very similar to that in the last examplealthough you'll still need to provide explicit encoding names when opening filethe file interface does most of the conversion work for you automatically unicode and byte strings