gratuitous new features in 2.0

Alex Martelli alex at magenta.com
Mon Aug 28 03:50:31 EDT 2000


"Pete Shinners" <pshinners at mediaone.net> wrote in message
news:JXcq5.12905$6T.1387590 at typhoon.we.rr.com...
> "Guido van Rossum" <guido at beopen.com> wrote
> > Because it is so much more general and powerful!  The teePrint
> > solution can easily be adapted to work with the extended print
> > statement:
> >
> >   def teePrint(files, *stuff):
> >       for file in files:
> >           for item in *stuff:
> >               print item,
> >           print
>
> am i missing something, or should this code have read...
>
>    def teePrint(files, *stuff):
>        for file in files:
>            for item in *stuff:
>                print >> file, item,
>            print >> file,
>
> i get confused the the BDFL makes programming errata.

I think both this code, _and_ the BDFL's, are wrong; which, to
my mind, speaks VOLUMES about what a blotch the 'print>>' thingy
really is. [I guess perfection is not of this world, and approaching
it too closely might bring the wrath and envy of the Gods; so, the
BDFL covertly decided to add one horrid wart to the otherwise-too-
good language (wisely, he placed it in a minor, out-of-the-way
corner...) and thereby avert the Furies' retribution].

In your code, I think the problem is the ending comma in the
    print >> file,
line, a comma which I believe is not supposed to be there.  The
'print >> file' syntax does not mesh very well with the 'print'
syntax:
if you have a statement
    print <things>
and want to change it so that it writes to 'file', rather than
to sys.stdout, then you must:
a] if <things> is a NON-empty set, then
    add >>file, right after print (WITH comma);
b] if <things> is *empty*, then
    add >>file  right after print (WITHOUT comma).


Not that the alternative of allowing (or requiring) the comma
even in case [b] would be that much better, since the terminating
comma to the print statement otherwise means to NOT add newline.

The impossibility of finding good syntax for a feature is just
one more indicator that the feature does not belong in the core
language, and should be re-cast as a function (or method).


Alex






More information about the Python-list mailing list