char 128? no... 256

Skip Montanaro skip at
Wed Feb 12 17:44:18 CET 2003

    >> To clarify, the TradeMark symbol is being transformed to Unicode
    >> #8482 automatically, presumably by COM or ADO. In Python, I do not
    >> know how I am supposed to be able to print (for example) the Unicode
    >> object I receive which contains this transformed TradeMark symbol.

Print it where?  To a file or a display device?  Remember, display devices
need to know the encoding of the data they receive as well.  For example, it
does me no good to print utf-8 encoded characters in an xterm, since it only
understands iso-8859-1.  On the other hand, I can set the charset of my
Mac's Terminal app windows to utf-8 and display all sorts of cool stuff.  In
this case, it appears the trademark sign is not available in iso-8859-1:

    >>> tm = u"\N{TRADE MARK SIGN}"
    >>> tm
    >>> tm.encode("latin-1")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    UnicodeEncodeError: 'latin-1' codec can't encode character '\u2122' in position 0: ordinal not in range(256)
    >>> tm.encode("utf-8")

so you're scrod unless you can find an encoding your display device knows
about which contains a trade mark sign.


More information about the Python-list mailing list