How to print non-printable chars??

coldpizza vriolk at gmail.com
Thu Aug 18 16:44:51 EDT 2011


On Aug 13, 7:59 am, Julio Cesar Rodriguez Cruz
<juliocesarrodriguezc... at gmail.com> wrote:
> Hi all,
> If I open an .exe file in any text editor I get lot of odd chars,
> what I want is to know how to output those chars if I have the hexadecimal
> code. I found out how to do the reverse process with the quopri module,
>
> i.e.:>>> import quopri
> >>> quopri.encodestring('ñè ')
> '=F1=E8=18'
> >>> quopri.decodestring('=F1=E8=18')
>
> '\xf1\xe8\x18'
>
> but how to do the reverse? ...gived '\xf1\xe8\x18', print 'ñè '
>
> any tips?
> thanks
> Julio Cesar

In a web/html environment or in broken ascii-only consoles like the
one on windows, I use the following hack:

print your_unicode_string.encode('us-ascii','xmlcharrefreplace')

This will print unicode chars using pure ASCII symbols which will
display correctly in a web browser and are more readable in a console
than unicode escapes.



More information about the Python-list mailing list