[Python-Dev] Indentation oddness...
robert.kern at gmail.com
Mon Jun 1 18:44:06 CEST 2009
On 2009-05-30 21:02, Greg Ewing wrote:
> Robert Kern wrote:
>> The 'single' mode, which is used for the REPL, is a bit different than
>> 'exec', which is used for modules. This difference lets you insert
>> "blank" lines of whitespace into a function definition without exiting
>> the definition.
> All that means is that the REPL needs to keep reading
> lines until it gets a completely blank one. I don't
> see why the compiler has to treat the source any
> differently once the REPL has decided how much text
> to feed it.
Not true. The REPL will keep reading lines until
compile(code,'<string>','single') passes without a SyntaxError. You can put in
blank lines when line continuation is implicit, like in the middle of a list.
This is the reason that there is a 'single' mode in the first place, to
determine when you've stopped typing. It's easier to add the grammar rule that a
block does not end with a line of whitespace to the compiler than to implement
all of the context-specific special cases for pure empty lines outside of the
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-Dev