[Python-Dev] PEP 259: Omit printing newline after newline

mcherm at destiny.com mcherm at destiny.com
Tue Jun 12 17:35:42 EDT 2001


It pains me to admit it <1.0 wink>, but Alex has done it again. He's 
taken a contentious discussion about a messy issue and, in his 
inimitable wordy manner, has clarified it and provided an excellent 
solution:


First, he says:

> So, summarizing: in Python, keyword statements either
> affect the namespace using them, or affect the control
> flow that uses them.
> 
> All, that is... except ONE.
> 
> That one is: print. 

Very interesting point. He goes on to say:

> Having output as a built-in function would encourage
> using it in lieu of the print statement,

(which is IMHO not so good)

>                                           which, in
> turn, would allow the usual kind of tricks that are
> available for built-ins but not for statements, such
> as wrapping/overriding

(which IMHO *IS* very good)

Then in a later message, he manages to pull it all together:

> If an output function were defined, it could play the
> same role wrt the print statement as __import__ plays
> wrt the import and from statements.  The statement
> would remain (of course: breaking a vast majority of
> all scripts would be silly), *AND* it would be
> defined and documented to internally invoke the function.
> 
> So the programmer gets a chance to "override" the
> function and get a global effect even when another
> module used the statement instead.  Perhaps, in this
> spirit, the function should be named __print__, then.

This is a REALLY GOOD SOLUTION!!!!!!!

(1) It keeps around the extremely-useful "print" statement.

(2) It allows "power-users" to intelligently modify the
    behavior of that statement.

(3) It does so in a pythonic way... working the same way
    as __import__, and REDUCING, not increasing the amount
    of "magic" in Python. (Currently "print" is magical
    with regard to space separation. To me it's somehow 
    better if that "magic" is a feature of some built-in
    default __print__ function rather than a feature of
    the opcode!)

And best of all.... if we'd had __print__ in the first
place, then >> would never have made it into the language!
<0.01 wink>.

So... I'm hoping that someone knowlegable will write this up
as a PEP to compete with 259. And I apologize to Guido for
having been one of the dev-reading-folks to encourage 259 in
the first place.

Ever-amazed-at-the-feats-of-knowledge-and-clarity-that-our-bots-are-
capable-of-ly yours,
Michael Chermside (mcherm at destiny.com)


PS: I believe no one should be asking others to do work
unless they're willing to volunteer to do it themselves. I'm 
really not knowlegable enough about Python yet to be a good 
PEP author. But if no one else steps forward to write it or
manages to convince me there's a better solution within, say
the next week, then I guess I've committed myself to writing
the PEP. Since I'm a lousy writer, I hope someone else likes
this idea and steps forward.






More information about the Python-list mailing list