unicode box drawing

Marc Christiansen usenet at solar-empire.de
Tue Mar 4 14:33:15 EST 2008


jefm <jef.mangelschots at gmail.com> wrote:
> How can I print the unicode box drawing characters in python:
> 
> 
> print u'\u2500'
> print u'\u2501'
> print u'\u2502'
> print u'\u2503'
> print u'\u2504'
> 
> Traceback (most recent call last):
>  File "\test.py", line 3, in ?
>    print u'\u2500'
>  File "C:\Python24\lib\encodings\cp1252.py", line 18, in encode
>    return codecs.charmap_encode(input,errors,encoding_map)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\u2500'
> in position 0: character maps to <undefined>

On linux in an utf8 console, it works with 2ython 2.4.4 and 2.5.1. It
looks like your python is using cp 1252 for output. Which does not
contain the box drawing characters. I don't think using a different
encoding would work (e.g. print u'\u2500'.encode('cp437'), or print
u'\u2500'.encode('utf8'))

Marc



More information about the Python-list mailing list