Why is there a different rule for blank lines in Python between the interactive prompt and when the program is run from shell as an executable?
Since blank lines are ignored, I enjoy using them abundantly. However, in the interactive prompt, a blank line is used to terminate a loop. Thus, I keep running into indentation errors when I paste a chunk of code into the interactive prompt as I would have blank lines throughout my loops. Consequently, this makes the interactive debugging/development process somewhat tedious. Putting a # instead of blank line helps, but I like my blank lines.
Even more annoying is different behavior between prompts (e.g., the Python shell and IPython). Where the Python interactive prompt would give me an error where I expect it, IPython would keep executing the indented code as if it was not part of loop without complaining.
I feel there is an easy solution out there, but I’m not aware of it. I am using vi for editing and Python/IPython prompts.
PEP 8 defines how blank lines should be used:
If you stick to the PEP, the only instance in which blank lines might generate problems in the interactive console are "blank lines in functions to indicate logical sections", I believe.
You can circumvent the problem like this though:
Note that using
\instead of#as you suggest in your question leaves the blank line… blank (as the\goes on the previous line).