Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60300
| References | <l6qacb$ap$1@ger.gmane.org> |
|---|---|
| Date | 2013-11-24 01:16 +1100 |
| Subject | Re: sys.stdout and Python3 |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3084.1385216188.18130.python-list@python.org> (permalink) |
On Sun, Nov 24, 2013 at 12:26 AM, Frank Millman <frank@chagford.com> 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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: sys.stdout and Python3 Chris Angelico <rosuav@gmail.com> - 2013-11-24 01:16 +1100
Re: sys.stdout and Python3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-24 14:31 +0000
Re: sys.stdout and Python3 Chris Angelico <rosuav@gmail.com> - 2013-11-25 01:39 +1100
csiph-web