How to print non-printable chars??

  • Thread starter Julio Cesar Rodriguez Cruz
  • Start date
J

Julio Cesar Rodriguez Cruz

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.:'\xf1\xe8\x18'

but how to do the reverse? ...gived '\xf1\xe8\x18', print 'ñè'

any tips?
thanks
Julio Cesar
 
N

Nobody

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.:
'\xf1\xe8\x18'

but how to do the reverse? ...gived '\xf1\xe8\x18', print 'ñè'

print(quopri.decodestring('=F1=E8=18'))
or:
sys.stdout.write(quopri.decodestring('=F1=E8=18'))

If you type an expression into the interactive Python interpreter, the
result is converted to a string using repr(); for strings, this converts
8-bit characters to their hexadecimal escape sequences, so that the result
only uses ASCII.

OTOH, the print statement converts values to strings using str(); for
strings, this is an identity operation (i.e. it returns the original
string untouched). Similarly, the .write() method of file objects uses str().
 
J

Julio Cesar

        print(quopri.decodestring('=F1=E8=18'))
or:
        sys.stdout.write(quopri.decodestring('=F1=E8=18'))

If you type an expression into the interactive Python interpreter, the
result is converted to a string using repr(); for strings, this converts
8-bit characters to their hexadecimal escape sequences, so that the result
only uses ASCII.

OTOH, the print statement converts values to strings using str(); for
strings, this is an identity operation (i.e. it returns the original
string untouched). Similarly, the .write() method of file objects uses str().

It just works!! thanks a lot and also for the explanations ;)
Cheers
Julio Cesar
 
C

coldpizza

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

'\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.
 
J

jmfauth

...

In a web/html environment or in broken ascii-only consoles like the
one on windows ...

C:\Users\Jean-Michel>echo 'Cet œuf de Lætitia coûte un €uro'
'Cet œuf de Lætitia coûte un €uro'

C:\Users\Jean-Michel>c:\Python27\python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
C:\Users\Jean-Michel>c:\Python32\python
Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
PS Cet œuf de Lætitia coûte un €uro ->
This Lætitia's egg costs one €uro'

PS2 "ñ" does not require special attention.

PS3 To the original question: This not a *coding* issue, it is a
character *representation* question.

jmf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top