[Python-ideas] A suggestion for Python 3 vs Python 2

Steven D'Aprano steve at pearwood.info
Tue Nov 12 16:56:34 CET 2013


On Tue, Nov 12, 2013 at 10:10:31PM +1000, Nick Coghlan wrote:
> On 12 November 2013 20:47, Ethan Furman <ethan at stoneleaf.us> wrote:
> > If you don't like `print()`, do a `p = print` and then all you have is `p()`
> > -- of course, you just lost a bunch a readability.
> >
> > But seriously, have often does any real program use print?
> 
> It's far more common in utility scripts (such as those written by
> system administrators) than it is in applications. The print change
> between Python 2 and 3 is one that doesn't really affect application
> developers all that much in practice (other than when trying things
> out in the REPL, and apparently not even then if using IPython), but
> can be more of an issue with those writing scripts where the standard
> streams are the primary IO mechanism.
> 
> We tend not to hear from the latter group as much as we do from
> application developers, though.

I've written a few short utility scripts in my time, and I rarely call 
print directly except for the most basic scripts. Normally I'll have 
facility to control output, perhaps a verbosity level, or at least a 
verbose flag, say:

def pr(message):
    if gVerbose:
        print message

So I think even in scripting, calling print directly is less common than 
it might otherwise seem.


-- 
Steven


More information about the Python-ideas mailing list