[Python-Dev] Replacement for print in Python 3.0

Guido van Rossum guido at python.org
Sun Sep 4 16:48:28 CEST 2005

On 9/4/05, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Keeping print as a statement is certainly one of the options I'm considering,
> so I don't think a counter-PEP is warranted just yet. There isn't even a PEP
> to be a counter to - it's all still on the Wiki at the moment.

I am so far a bit disappointed by the wiki contents; I'm hoping on
more of a summary of the argumentation and use cases; instead, I found
wild proposals that have zero chance of making it.

> The more I play with it, the more I believe the part I have a problem with is
> a weakness in the string formatting for iterables.

I've noticed. I think you should cool down a bit about this.
Automatically consuming iterables can have serious side effects (like
reading a file to the end!), which you generally want to avoid.
Putting complex syntax in %xyz format strings for iterators seems like
a poor choice of tool -- it is already complex and brittle. All *my*
sequence printing needs are generally met by a simple for loop or
",".join(...). If that's still too much typing for you, and you really
think that the use case of printing all items in an iterable is common
enough to warrant standard library support, I'd suggest something
along these lines:

def printseq(seq, sep=" ", to=None):
    if to is None:
        to = sys.stdout # dynamic default
    firsttime = True
    for item in seq:
        if firsttime:
            firsttime = False
            printbare(sep, to=to)
        printbare(item, to=to)

# printbare() is just a suggestion; I'm not too happy with the name.

> The point about not needing parentheses for conditionals where a lot of other
> languages require them is a good one - I'm sure I write print statements
> nearly as often as I write conditionals.

I'm sad to see that all the good software engineering habits are
dropped the moment people have to type a pair of extra parentheses.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list