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

人言落日是天涯,望极天涯不见家 kelvin.you at gmail.com
Wed May 30 11:01:03 EDT 2007


On 5月30日, 下午9时03分, Tijs <tijs_n... at artsoftonline.com> wrote:
> ??????????????? 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

Yes, it works, thank you.
But I doubt this way may not work on linux.  Maybe I should write some
additional code for supporting both windows and linux OS.




More information about the Python-list mailing list