Python indentation in "empty lines"

nisc picture nisc · Apr 28, 2010 · Viewed 10.8k times · Source

Which is preferred ("." indicating whitespace)?

A)

def foo():
    x = 1
    y = 2
....
    if True:
        bar()

B)

def foo():
    x = 1
    y = 2

    if True:
        bar()

My intuition would be B (that's also what vim does for me), but I see people using A) all the time. Is it just because most of the editors out there are broken?

Answer

YOU picture YOU · Apr 28, 2010

If you use A, you could copy paste your block in python shell, B will get unexpected indentation error.