[Python-Dev] Replacement for print in Python 3.0

Steven Bethard steven.bethard at gmail.com
Fri Sep 2 22:26:51 CEST 2005

Paul Moore wrote:
> Interestingly enough, the other languages I use most (C, Java,
> VB(Script) and Javascript (under Windows Scripting Host)) all use
> functions for output. Except for C, I uniformly dislike the resulting
> code - the output structure gets hopelessly lost under the weight of
> string concatenation and explicitly added spaces.

Are your complaints about Guido's proposal or mine?  The complaint
above doesn't quite seem relevant to my proposal, which retains the
space-insertion.  Basically, my proposal suggests that files (and
other streams) gain a print method like:

    class file(object):
        def print(self, *args):
            self.write(' '.join(str(arg) for arg in args))

and the print statement becomes the builtin print() function, defined like:

    def print(*args):

Looking at your use cases, this seems to cover them pretty well:

> - Debugging, most definitely. Adding a quick print "a =", a is often
> all that's needed.

Use the builtin print():

    print('a =', a)

> - Logging, sometimes. When I just want some basic output, and don't
> want to deal with the complexity of the logging package.

Use the builtin print():

    print('some logging message', foo)

> - Unix-style command-line utilities, where textual output to stdout is the norm.

Use the builtin print():

    print('line of output')

> - Error and help messages, often with print >>sys.stderr

Use the print() method of sys.stderr:

    sys.stderr.print('error or help message')

You can wordify anything if you just verb it.
        --- Bucky Katt, Get Fuzzy

More information about the Python-Dev mailing list