print , (was Re: Python vs. Perl, which is better to learn?)

Alex Martelli aleax at aleax.it
Fri May 3 03:10:27 EDT 2002


Paul Rubin wrote:

> aahz at pythoncraft.com (Aahz) writes:
>> Let this be a lesson to you newbies.  ;-)  (But I have no clue what
>> lesson it should be...)
> 
> It means print is even more complicated than I thought.  I'm sorry but
> I still consider the extra spaces from the print statement to be a
> Python wart.  Perl prints exactly what you tell it to, and I believe
> that's the correct behavior.  "Explicit is better than implicit".

I find Python's print convenient for debugging purposes, and that's
about all.  No matter how refined the theoretical possibilities, some
of us dinosaurs, at times, feel most comfortable rapidly sticking print
statements at strategic points in the code to follow the control flow
and data values, then commenting some of them out again, and so
on.  For this purpose, print's "convenience" features are just fine --
they save me a fraction of a second each time wrt explicitly using
blanks, str calls, etc, or a formatstring.  I've seen some beginners
appreciate it similarly -- it's simplest to use for beginners' typically
simple requirements (you could see this as a subcase of 'debugging',
in that a beginner's often debugging his or her own knowlegde of
the language;-).

Beyond such uses, for which it's fine, print can indeed be considered
a minor wart.  It 'should' surely not be a statement, but a function
(probably; perhaps a fileobject method, but i'm inclined to function by
analogy with many other builtins -- the fileobject's responsibilities are
embodied in the write method, just as other arguments are accessed
through their stringification, only).

Maybe (in the abstract -- backwards compatibility surely makes the
change unfeasible now) print should be indeed a statement, but one
much like assert -- to be ignored when Python is run with -O.  After
all, one doesn't use -O when debugging, or learning the language:-).
Being a statement would be justified by the ignore-unless-debugging
feature (a function would have its arguments evaluated anyway, thus
paying substantial runtime price uselessly).  Just musing...


Alex




More information about the Python-list mailing list