Python scoping

Grant Edwards grante at visi.com
Fri Oct 27 12:43:31 EDT 2000


In article <8FD6F80F0suppamanxcollectoror at 209.155.56.95>, SuppamanX wrote:

>   I have been using Python off and on for 6 months now and have grown to 
>love it from the beginning. However, there is a facett of Python that 
>annoys me somewhat. It is the 'scoping by indentation'. Coming from a 
>background of 'formal' languages (e.g. Pascal, C, Java,...), I am 
>accustomed to explicitly start and end my scopes with a braces.

Perhaps you already know this, and I'm about to sound overly
pedantic, but...

You're mixing together two different things: scoping and
statement grouping.  They're two different (though in many
languages not orthogonal) things.  In C, Pascal, Java, the
_same_ method is used for both scoping and grouping statements:
the begin/end tokens and curly-braces do two distinct things:
delimit a scope _and_ group multiple statements into a single
"statement".

In Python, indentation is used to group statements but it is
not used for scoping, as you seem to indicate.

>Can someone clarify why there is no explicit end for scopes?
>(i.e. IFs, FORs, WHILEs, METHODs, etc...)

In python, IF, FOR, WHILE do not start a new scope.  The only
thing that starts a new scope is a function definition.

-- 
Grant Edwards                   grante             Yow!  BRILL CREAM is
                                  at               CREAM O' WHEAT in another
                               visi.com            DIMENSION...



More information about the Python-list mailing list