Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11335
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Subject | Re: How to print non-printable chars?? |
| Date | 2011-08-13 06:22 +0100 |
| Message-Id | <pan.2011.08.13.05.22.21.718000@nowhere.com> |
| Newsgroups | comp.lang.python |
| References | <mailman.2249.1313211585.1164.python-list@python.org> |
| Organization | Zen Internet |
On Sat, 13 Aug 2011 00:59:42 -0400, Julio Cesar Rodriguez Cruz 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 'ñè'
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().
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to print non-printable chars?? Julio Cesar Rodriguez Cruz <juliocesarrodriguezcruz@gmail.com> - 2011-08-13 00:59 -0400
Re: How to print non-printable chars?? Nobody <nobody@nowhere.com> - 2011-08-13 06:22 +0100
Re: How to print non-printable chars?? Julio Cesar <juliocesarrodriguezcruz@gmail.com> - 2011-08-12 22:55 -0700
Re: How to print non-printable chars?? coldpizza <vriolk@gmail.com> - 2011-08-18 13:44 -0700
Re: How to print non-printable chars?? jmfauth <wxjmfauth@gmail.com> - 2011-08-19 08:07 -0700
csiph-web