sys.stdout.detach() results in ValueError
Peter Kleiweg
pkleiweg at xs4all.nl
Wed Mar 7 17:35:46 EST 2012
Dave Angel schreef op de 7e dag van de lentemaand van het jaar 2012:
> On 03/07/2012 02:41 PM, Peter Kleiweg wrote:
> > I want to write out some binary data to stdout in Python3. I
> > thought the way to do this was to call detach on sys.stdout. But
> > apparently, you can't. Here is a minimal script:
> >
> > #!/usr/bin/env python3.1
> > import sys
> > fp = sys.stdout.detach()
> >
> > Not yet using fp in any way, this script gives the following error:
> >
> > Exception ValueError: 'underlying buffer has been detached' in
> >
> > Same in Python 3.1.4 and Python 3.2.2
> >
> > So, what do I do if I want to send binary data to stdout?
> >
> >
> >
>
> sys.stdout.write( some_binary_data )
TypeError: must be str, not bytes
--
Peter Kleiweg
http://pkleiweg.home.xs4all.nl/
More information about the Python-list
mailing list