2016-12-13 | Paul Boddie | file changeset files shortlog | Added encoding attributes and text encoding/decoding support to file streams. Added a test of Unicode object creation and output. |
paul@392 | 1 | # -*- coding: ISO-8859-1 -*- |
paul@392 | 2 | |
paul@392 | 3 | import sys |
paul@392 | 4 | |
paul@392 | 5 | # Print bytes. |
paul@392 | 6 | |
paul@392 | 7 | s = "???" |
paul@392 | 8 | print s # ??? |
paul@392 | 9 | |
paul@392 | 10 | # Obtain text and print it. |
paul@392 | 11 | |
paul@392 | 12 | u = unicode(s, "ISO-8859-1") |
paul@392 | 13 | print u # ?????? |
paul@392 | 14 | print u.encode("ISO-8859-1") # ??? |
paul@392 | 15 | |
paul@392 | 16 | # Inspect and update the encoding of stdout. |
paul@392 | 17 | |
paul@392 | 18 | print sys.stdout.encoding # None |
paul@392 | 19 | sys.stdout.encoding = "ISO-8859-1" |
paul@392 | 20 | print u # ??? |