1 # -*- coding: ISO-8859-1 -*- 2 3 import sys 4 5 # Print bytes. 6 7 s = b"???" 8 print s # ??? 9 10 # Obtain text and print it. 11 12 # Explicitly from bytes. 13 14 u = unicode("???", "ISO-8859-1") 15 print u # ?????? 16 print u.encode("ISO-8859-1") # ??? 17 18 # Explicitly from Unicode literals. 19 20 u2 = u"???" 21 print u2 # ?????? 22 print u2.encode("ISO-8859-1") # ??? 23 24 # Implicitly from string literals. 25 26 #u3 = "???" 27 #print u3 # ?????? 28 #print u3.encode("ISO-8859-1") # ??? 29 30 # Combine bytes and text. 31 # The text should be decoded. 32 33 su = s + u 34 print su # ?????? 35 36 # Combine text and bytes. 37 # The text should be decoded. 38 39 us = u + s 40 print us # ?????? 41 42 # Inspect and update the encoding of stdout. 43 44 print sys.stdout.encoding # None 45 sys.stdout.encoding = "ISO-8859-1" 46 print u # ??? 47 print su # ?????? 48 print us # ??????