[Python-Dev] extended print statement, uPre-PEP

Barry A. Warsaw bwarsaw@beopen.com
Sat, 22 Jul 2000 00:47:32 -0400 (EDT)

I've long wanted to make the print statement able to handle
alternative output files in a more convenient syntax.  Yes you can
rebind sys.stdout, but that is often very clumsy to get right in the
face of exceptions.

All the talk about extra operators has made me giddy (no, not geddy :)
so my proposal is to allow `@' after the print keyword using syntax
such as:

    print @ sys.stderr, 'hello'

The thing between the @ and the , must be an expression yeilding an
object with a write() method, otherwise you'd get a runtime exception
(probably TypeError).  Thus, these two are equivalent:

    print @ sys.stdout, 'wassup?'
    print 'wassup?'

It makes it quite convenient to do things like:

    f = open('log, 'w')
    print @ f, 'starting'
    print @ f, 'ending'

etc., etc.

I started hacking on the grammar to play with this, but haven't gotten
very far, and I'm way too tired to continue tonight.  I'd continue
though if there's positive feedback.