From: Thomas H. <th...@py...> - 2006-02-02 12:44:19
|
Alex Tweedly <al...@tw...> writes: > If I start up the Python interpreter (i.e. open a DOS shell box, and > type "python") I get my Python interpreter. I then type in the > following two lines, and get an error : > >> C:\Documents and Settings\Eleane>python >> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> s = u'a\u2019s' >> >>> print s >> Traceback (most recent call last): >> File "<stdin>", line 1, in ? >> File "C:\Python24\lib\encodings\cp850.py", line 18, in encode >> return codecs.charmap_encode(input,errors,encoding_map) >> UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019' >> in position >> 1: character maps to <undefined> >> >>> There are unicode characters (maybe the correct term is codepoint, but I'm far from an expert) that can not be converted to code page 850, which the console uses in your case (*). It is not that obvious for the apostrophe-like character you have above, but obvious for, say, chinese or japanese characters if you are using a western windows. > If instead I start the PythonCard codeEditor, and start a Shell (F5), > and type the same two lines, it works properly. Is that a graphical shell? If so, it probably understands unicode (obviously). (*) The windows XP console, at least, is able to handle unicode, but afaik Python uses the ansi apis to write to stdout. Thomas |