Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'sys': 0.05; 'python': 0.08; 'valueerror:': 0.09; 'error:': 0.10; 'exception': 0.12; 'binary': 0.13; 'detach': 0.16; 'received:192.168.1.104': 0.16; 'stdout': 0.16; 'subject:() ': 0.16; 'cc:addr:python-list': 0.16; 'question.': 0.16; 'wrote:': 0.18; 'subject:skip:s 10': 0.18; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.26; 'import': 0.27; 'script': 0.28; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'yet': 0.32; 'header :User-Agent:1': 0.33; 'skip:# 10': 0.34; 'minimal': 0.37; 'but': 0.37; 'using': 0.37; 'received:192': 0.38; 'some': 0.38; 'should': 0.38; 'data': 0.38; 'received:192.168.1': 0.39; 'here': 0.64; 'header:Reply-To:1': 0.70; 'reply-to:no real name:2**0': 0.72; 'funny': 0.76; 'clearer': 0.84; 'stdout?': 0.84; 'sys.stdout.': 0.84 Date: Wed, 07 Mar 2012 17:14:35 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.27) Gecko/20120216 Thunderbird/3.1.19 MIME-Version: 1.0 To: Peter Kleiweg Subject: Re: sys.stdout.detach() results in ValueError References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:1yK1vDQ/INfKtLteQUdcTLcReTpX1ygXxauRcW/nNDh n0hjxWhqEp3qc74jNcpAuBkj0rGX4n4ZhDCa6GqUQjzDJ0YAY7 pKF+jmflaTxHwXsrr1e18Q9bvp5GVLcRd9lhZEjtQ9+QA8lG8P QSAjYa4xkOvgd1qVSgY1gbxDUTen4MyS2qRwLIbifFP6IazsLm FrS0xwExoDS0RB3+U4HmBqIt7OJRXSu9qGPWdOR9NNr2fYBnCa 9Y6jbvCkW8ODlT98RsqSoS3CFIvs4Nwb9oOGhxRN1MTAwRXeUT 5Y3mETWy+8OuClpz7CxvKyxln0mI8UYfvts5r4zpevmUQyPZQ= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331158511 news.xs4all.nl 6873 [2001:888:2000:d::a6]:33289 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21358 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 ) Why should you need to do some funny manipulation? If you have some other unstated motivation, better ask a clearer question. -- DaveA