[Python-Dev] Replacement for print in Python 3.0

Martin Blais martin.blais at gmail.com
Sat Sep 3 01:34:31 CEST 2005

On 9/2/05, Steven Bethard <steven.bethard at gmail.com> wrote:
> 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))
>             self.write('\n')
> and the print statement becomes the builtin print() function, defined like:
>     def print(*args):
>         sys.stdout.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')

Wow, that's so cool actually, you make the concept of "print'ing" even
more regular (on all file objects, and then builtin print is just like
general print'ing, except for sys.stdout), we don't need a keyword
argument for the stream anymore, and the special statement goes away.

And if you like concise, then you could do something like this::

   perr = sys.stderr.print
   perr("Error: comfobulator failed to initialize doogledigook.")

I like it so much that my mind is wandering about hacking my
sitecustomize.py to inject it in __builtin__ so I can start using it
right now...  +1

Also, you're making a point that I think seem to be missing: it's
REALLY just about a couple of parentheses.  Print statement without
parens, print with parens.... same stuff.  It's a builtin, it's still
always there, and so it's still a convenient as before, except you
have to type parentheses.  On the upside: one less quirk/exception in
the language (one more tiny step towards lisp, me love that, simple is
good).  I don't think that it would make it harder on the newbies
either: less stuff to learn, it's just a function!

Someone above proposed a string of one char as last argument would
trigger the no-newline case.  Why not use an empty string instead?

   print("Incomplete line", '')

Seems like the thing that would disrupt print the least is an empty
string...  The special meaning is implied.  Or if you want more
verbose, a special symbol/value in a convenient namespace:

   print("Incomplete line", print.cont)


More information about the Python-Dev mailing list