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


Groups > comp.lang.python > #112292

Re: print() function with encoding= and errors= parameters?

From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: print() function with encoding= and errors= parameters?
Date 2016-08-03 10:05 -0400
Message-ID <mailman.145.1470233115.6033.python-list@python.org> (permalink)
References <1470227371.397715.684773553.140807A6@webmail.messagingengine.com> <1470233112.2667238.684861393.67022A98@webmail.messagingengine.com>

Show all headers | View raw


On Wed, Aug 3, 2016, at 08:29, Malcolm Greene wrote:
> Looking for a way to use the Python 3 print() function with encoding and
> errors parameters.
> 
> Are there any concerns with closing and re-opening sys.stdout so
> sys.stdout has a specific encoding and errors behavior? Would this break
> other standard libraries that depend on sys.stdout being configured a
> specific way?

You could duplicate stdout [open(os.dup(sys.stdout.fileno()), ...)]

You could make an IO class which sends bytes output to sys.stdout.buffer
but won't close it when closed (you know, it'd be nice to be able to
have "not owned underlying stream" as an option of the standard IO
classes)

If your output isn't going to be long, you could print everything to a
StringIO and then write to sys.stdout.buffer at the end.

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


Thread

Re: print() function with encoding= and errors= parameters? Random832 <random832@fastmail.com> - 2016-08-03 10:05 -0400

csiph-web