[Tutor] The 'print >>' ogre

dman dsh8290@rit.edu
Sun, 17 Feb 2002 15:08:08 -0500

On Sun, Feb 17, 2002 at 02:36:49PM -0500, Pijus Virketis wrote:
| > I've used it.  The idea of directly printing to a file isn't the
| > problem.  There are times when it's downright handy.  It's the syntax
| > that's ogreish (yes that really is a word).  But I've used far uglier
| > constructs in other languages so I can live with print >>.
| I personally rather like the >> ogre. Has no one else seen Shrek here? :)

I just saw it Friday night.  Good movie.

| I also remember reading a small article by Guido on the python.org
| website after the first version of Python with the feature came out,
| where he highlighted it, along with "+=" operators, as features
| often requested and used by programmers. But, if you don't dig it,
| what would be a more Pythonesque way of accomplishing the same task?
| If you had to do a PEP, what syntactical alternatives would you
| propose?

There's the crux of the matter.  I like the feature, just not the
syntax.  I don't know what would be the Right syntax for it.  (Does
"I'll know it when I see it count"?)  The "fprint" idea with the file
as the first arg isn't too bad.  It would probably be better as a
function instead of a statement/keyword, though.  Perhaps "print"
should be turned into a function?[1]  Or perhaps "print" should be a
method on file objects, and 'stdout' become a built-in name.  It would
make it more consistent overall, and follow the "explicit, not
implicit" rule.

For example :

# current style
print "Hello World"
print >> some_file , "Hello World"
some_file.write( "a string" ) # not quite the same as 'print'

# contemplated style
stdout.print( "Hello World" )
some_file.print( "Hello World" )
some_file.write( "a string" ) # the same as it has always been

just-some-semi-random-thinking-out-loud-ly y'rs

[1] aside from backwards compatibility issues


How to shoot yourself in the foot with Java:

You find that Microsoft and Sun have released imcompatible class
libraries both implementing Gun objects. You then find that although
there are plenty of feet objects implemented in the past in many other
languages, you cannot get access to one. But seeing as Java is so cool,
you dont care and go around shooting anything else you can find.
    (written by Mark Hammond)