[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

unicode box drawing

jefm

3/4/2008 5:52:00 PM

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>
4 Answers

Nanjundi

3/4/2008 6:42:00 PM

0

On Mar 4, 12:51 pm, jefm <jef.mangelsch...@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>

Just FYI, not an answer.

It works like a charm on linux (ubuntu, fc3, python 2.4.1 & 2.5.2)

Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'\u2500'
-
>>> print u'\u2501'
?
>>> print u'\u2502'
¦
>>> print u'\u2503'
?
>>>
>>> print u'\u2504'
?

on windows using python 2.4. ???
-N

Marc Christiansen

3/4/2008 7:33:00 PM

0

jefm <jef.mangelschots@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

jefm

3/4/2008 9:12:00 PM

0

> on windows using python 2.4. ???

yes, as a matter of fact I am.
Did not feel the need to switch to 2.5 yet.
I'm gonna give this a try, but it requires me to dig up 2.5 versions
of the libraries i am using.
(one of them didn't at the time and that is why I stuck to 2.4)

jefm

3/4/2008 9:39:00 PM

0

> on windows using python 2.4. ???


I was on Python 2.4.3 and it gave me that problem.
I upgraded to 2.4.4 and it works.
thanks for the tip.