Printing characters outside of the ASCII range

Dave Angel d at davea.name
Fri Nov 9 12:47:42 EST 2012


On 11/09/2012 12:17 PM, danielk wrote:
> I'm converting an application to Python 3. The app works fine on Python 2.
>
> Simply put, this simple one-liner:
>
> print(chr(254))
>
> errors out with:
>
> Traceback (most recent call last):
>   File "D:\home\python\tst.py", line 1, in <module>
>     print(chr(254))
>   File "C:\Python33\lib\encodings\cp437.py", line 19, in encode
>     return codecs.charmap_encode(input,self.errors,encoding_map)[0]
> UnicodeEncodeError: 'charmap' codec can't encode character '\xfe' in position 0: character maps to <undefined>
>
> I'm using this character as a delimiter in my application.
>
> What do I have to do to convert this string so that it does not error out?

What character do you want?  What characters do your console handle
directly?  What does a "delimiter" mean for your particular console?

Or are you just printing it for the fun of it, and the real purpose is
for further processing, which will not go to the console?

What kind of things will it be separating?  (strings, bytes ?)  Clearly
you originally picked it as something unlikely to occur in those elements.

When those things are combined with a separator between, how are the
results going to be used?  Saved to a file?  Printed to console?  What?

-- 

DaveA




More information about the Python-list mailing list