How to print this character u'\u20ac' to DOS terminal

Tijs tijs_news at artsoftonline.com
Wed May 30 09:03:08 EDT 2007


??????????????? wrote:

> But the string contained the u'\u20ac' is get from remote host. Is
> there any method to decode it to the local 'mbcs'?

remote_string = u'\u20ac'
try:
   local_string = remote_string.encode('mbcs')
except:
   # no mbcs equivalent available
   print "encoding error"
else:
   # local_string is now an 8-bit string
   print "result:", local_string
   # if console is not mbcs, you should see incorrect result
   assert result == '\x80'

Mbcs is windows-only so I couldn't test this. 

If your application handles text, it may be easier to just leave everything
in Unicode and encode to utf-8 for storage?

Regards,
Tijs



More information about the Python-list mailing list