gratuitous new features in 2.0

Andrew Dalke dalke at acm.org
Sat Aug 26 19:16:33 EDT 2000


Guido wrote:
>Now you are asked to make it print to another file -- a standard
>example of how software typically is asked to evolve.

>It's possible that for Python 3000 we decide to deprecate print in
>favor of a write() function.  But for Python 2.0, there's no
>deprecating print just doesn't seem to be the right thing to do.

I already do that.  print is for interactive mode (just like "import *"),
debugging and for top-level code which will never be used in a library.
Everything else takes a file-like object using write.

I've no problem with print as-is (without even the '>>').  Allowing
it is fine, but even then using it has the lookup overhead that a
write=outfile.write doesn't.  (Did I say someone say the disk is slow?
Then use a cStringIO and dump the whole output when finished.)

Hmm, there is a problem mixing the two mechanisms.  Some of my code
just passes the 'write' function/method, and not the file object.  This
could not be passed to a library expecting a file object for use with
'>>', at least, not without a wrapper object.  Allowing '>>' means you
can have libraries which don't talk to each other very easily.  Unless
"print >> write_function" checks for the "write" method and if that
fails, if it's callable.  Ugh.

So I suppose allow it but no one in my shop will use it in most code.
Oh wait, I'm a one person shop, so I guess that doesn't count :)

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list