unicode box drawing

J

jefm

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>
 
N

Nanjundi

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.©¨

on windows using python 2.4. ???
-N
 
M

Marc Christiansen

jefm said:
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
 
J

jefm

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)
 
J

jefm

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top