running python 2 vs 3

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Mar 20 20:59:57 EDT 2014


On Thu, 20 Mar 2014 22:50:45 +0200, Marko Rauhamaa wrote:

> Mark Lawrence <breamoreboy at yahoo.co.uk>:
> 
>> On 20/03/2014 20:30, Marko Rauhamaa wrote:
>>> I must say, though, that Python3 destroyed "print" forever for me. To
>>> avoid nausea, I write sys.stdout.write() in all Python3 code.
>>
>> Not for me, I was using from __future__ import print_function for years
>> so got used to typing those two extra brackets, plus print very kindly
>> inserts the newlines for me.
> 
> That very realization helped me wean myself from "print." Its sole
> raison d'être is the insertion of the newline, which it would be nicer
> to micromanage anyway; that's how it's done in other programming
> languages as well: C, perl, guile, ... (Well, ok, "echo" is the
> exception.)

echo is not "the" exception. *Many* languages handle the newline when 
printing: Pascal, Ruby, Io, Dylan, Haskell, Rebol, Tcl, Perl6, Java, 
Ocaml, ... either add a newline by default, or provide two functions for 
printing, one which adds newline and one which doesn't.

The rule of three applies here: anything you do in three different places 
ought to be managed by a function. Printing a newline at the end of a 
line of output is *incredibly* common. Any language which fails to 
provide a print-with-newline function is, frankly, sub-standard.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list