Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91300

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)

References (1 earlier) <techtonik@gmail.com> <CAPkN8xK452YWZvVRipTjq05eKthxEE28CB5W5-MN+6DZnXHOGg@mail.gmail.com> <201505271135.t4RBZY6F013836@fido.openend.se> <CAPkN8xJGnut_V0BmEah1ravN3cXESqx7c6U=mOAS0coD3fcPjA@mail.gmail.com> <CAPkN8xJTA_cfWuXD8+MUqKB6yTMp=vzUHk0sQsNz3acyJL-LXg@mail.gmail.com>
Date 2015-05-27 21:59 +1000
Subject Re: Fwd: Lossless bulletproof conversion to unicode (backslashing)
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.84.1432727951.5151.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, May 27, 2015 at 9:52 PM, anatoly techtonik <techtonik@gmail.com> wrote:
> And the short answer is that we need unicode because we are printing this
> information to the stdout, and stdout is opened in text mode at least on
> Windows, and without explicit conversion, Python will try to decode stuff
> as being `ascii` and fail anyway.

So you're working with text. That means you HAVE to decode it somehow;
you fundamentally cannot print bytes to the console. Lossless
concealment of arbitrary bytes won't help you. If you can't adequately
decode everything, either backslash-escape the rest, or use a
replacement character; you can't print out those bytes.

And no, I will not cc you. Subscribe to the list if you're going to
ask a question.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) Chris Angelico <rosuav@gmail.com> - 2015-05-27 21:59 +1000

csiph-web