[Tutor] Problems with genetically engineering the Print Ogre

Scot Stevenson scot@possum.in-berlin.de
Wed, 27 Feb 2002 10:23:40 +0100

Hello there, 

I have been learning Python for about half a year now, and there are two 
parts of the language that feel "wrong" and do not have the instant, 
instantly logical syntax that makes the rest of the language unbelievably 

a) List comprehensions (aka "Ugly Stuff in Square Brackets")
b) The extrended print statement (aka "The Print Ogre")

Neither "[<exp> for <var> in <seq> if <con>]" nor "print >> <file>, 
<stuff>" are intuitive in the way that "if <con>:" or "for <var> in 
<seq>:" are. They are, in fact, terribly confusing if Python is your first 
language. Both create ugly spots of strange characters in code listings, 
and I think both should be dragged outside and shot, or at least 
genetically engineered to something that doesn't look like it has a "Made 
by Frankenstein" stamp on the bottom. My first reaction to list 
comprehensions was: How the hell did /that/ get past the beauty checker?

However, to finally get to the point of this mail, some of the saner ideas 
in the PEP to the Print Ogre were vetoed by the BDFL himself. From PEP 214:


    The proposal has been challenged on the newsgroup.  One series of
    challenges doesn't like '>>' and would rather see some other

    Challenge: Why not one of these?

        print in stderr items,.... 
        print + stderr items,.......
        print[stderr] items,.....
        print to stderr items,.....

    Response: If we want to use a special symbol (print <symbol>
    expression), the Python parser requires that it is not already a
    symbol that can start an expression -- otherwise it can't decide
    which form of print statement is used.  (The Python parser is a
    simple LL(1) or recursive descent parser.)


This might be perfectly clear to Real Computer Scientists, but as one of 
those people who is slightly more fluent in Mandarin than Recursive 
Descent Parsing, I don't see why we can't at least change the Print Ogre 
into something clean and instantly understandable like "print to <file>, 
<stuff>", which would be the sort of syntax I would expect (actually, 
"print <stuff> to <file>" would be even better, but sticking stuff at the 
end would make this look like a German verb pattern; "print to <file>: 
<stuff>" would be good, too, but break the rule about indentation after 
":", which I understand). 

Is there any chance one of the other Real Computer Scientists on this list 
could explain what the problem is? 

Y, Scot