Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'assign': 0.07; 'string': 0.09; 'happen.': 0.09; 'newline': 0.09; 'subject:Python3': 0.09; 'terminated': 0.09; '24,': 0.16; 'differs': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'interpreter,': 0.16; 'repl': 0.16; 'script,': 0.16; 'sys.stdout': 0.16; 'written.': 0.16; 'prevent': 0.16; 'wrote:': 0.18; 'handles': 0.22; 'skip:_ 20': 0.27; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'there,': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'two': 0.37; 'nov': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'length': 0.61; 'between': 0.67; 'frank': 0.68; 'confusing': 0.84; 'improvement,': 0.84; 'overall,': 0.84; 'partial': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=vDOQQdk4qyY785kdS2SQf0KbN4ADSJIFZUJJRdjlbAo=; b=WmTNvEqd1XXEsUu2za5tXm5fRcPzBJ37msyiU1gPDgJ1Jb1z1oJlWNzrynMBlnscXd PV2mLs9eAkPGEhXu63B8fhqZjJJftPZ0pBvtYsFnjS8vTIqwuf4T4vhjXDV6MTqyMddU me3tEqsl7Ma0nxBB5G4SEmr1jXk48AfwYloK89/nbPj+ibYH7RStSksGyAvBu2t9EdlJ 8mxd8XLjsRPvyR5LV5nmhWsTbXZ3aZQl9vd6UxJg6YlWAdFGt6fW3MOV446/moAnPQUo MW2g4GVlEamWfLL/Jl6u9FPoRCru1iM+fWv14G22itGpt+HbTdReATGlj1F4RIfGDWEf pkRA== MIME-Version: 1.0 X-Received: by 10.69.31.1 with SMTP id ki1mr8253685pbd.124.1385216178955; Sat, 23 Nov 2013 06:16:18 -0800 (PST) In-Reply-To: References: Date: Sun, 24 Nov 2013 01:16:18 +1100 Subject: Re: sys.stdout and Python3 From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385216188 news.xs4all.nl 15986 [2001:888:2000:d::a6]:42748 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60300 On Sun, Nov 24, 2013 at 12:26 AM, Frank Millman wrote: > for i in range(10): > sys.stdout.write('.') > sys.stdout.flush() > time.sleep(1) > sys.stdout.write('\n') > > I tried it under Python3, and found that it differs in two ways - > > 1. Each 'write' is terminated by a newline > 2. Each 'write' appends the length of the string written. Only in the interactive interpreter, where return values get printed. In a script, that won't happen. To prevent that from happening interactively, just assign the result to something: for i in range(10): _=sys.stdout.write(".") sys.stdout.flush() There definitely is a difference between Py2 and Py3 there, but it's nothing to do with sys.stdout - it's a change in the REPL (interactive interpreter, Read/Eval/Print Loop) and how it handles return values inside loops. I think it's an improvement, overall, though it is a little confusing when you work with partial output. ChrisA