469,898 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Re: Unicode chr(150) en dash

"C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 149, in
execute query = query.encode(charset) UnicodeEncodeError: 'latin-1'
codec can't encode character u'\u2013' in position 52: ordinal not in
range(256)
Here it complains that it deals with the character U+2013, which
is "EN DASH"; it complains that the encoding called "latin-1" does
not support that character.

That is a fact - Latin-1 does not support EN DASH.
When I type 'print chr(150)' into a python command line window I get
a LATIN SMALL LETTER U WITH CIRCUMFLEX
(http://www.fileformat.info/info/unic...0fb/index.htm),
That's because your console uses the code page 437:

pychr(150).decode("cp437")
u'\xfb'
pyunicodedata.name(_)
'LATIN SMALL LETTER U WITH CIRCUMFLEX'

Code page 437, on your system, is the "OEM code page".
but when I do so into a IDLE window I get a hypen (chr(45).
That's because IDLE uses the "ANSI code page" of your system,
which is windows code page 1252.

pychr(150).decode("windows-1252")
u'\u2013'
pyunicodedata.name(_)
'EN DASH'

You actually *don't* get the character U+002D, HYPHEN-MINUS,
displayed - just a character that has, in your font, a glyph
which looks similar to the glyph for HYPHEN-MINUS.
However, HYPHEN-MINUS and EN DASH are different characters, and
IDLE displays the latter, not the former.
I tried searching "en dash" or even "dash" into the encodings folder
of python Lib, but I couldn't find anything.
You didn't ask a specific question, so I assume you are primarily
after an explanation.

HTH,
Martin
Jun 27 '08 #1
0 1957

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Damjan | last post: by
2 posts views Thread by gdetre | last post: by
15 posts views Thread by luc.saffre | last post: by
232 posts views Thread by robert maas, see http://tinyurl.com/uh3t | last post: by
6 posts views Thread by hdante | last post: by
16 posts views Thread by Laszlo Nagy | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.