Is an interactive command a block?

Alf P. Steinbach alfps at start.no
Fri Nov 20 16:23:48 CET 2009


* Benjamin Kaplan:
> On Thu, Nov 19, 2009 at 4:42 PM, Alf P. Steinbach <alfps at start.no> wrote:
>> * Steven D'Aprano:
>>
>> I feel that there's still something lacking in my understanding though, like
>> how/where the "really actually just pure local not also global" is defined
>> for function definition, but it's now just a vague feeling of something
>> missing, not a feeling of direct contradiction as I had when I believed
>> local != global.
>>
> 
> It's because the only blocks in python that have their own scope are
> classes and functions. For loops don't have their own scope- they use
> the enclosing one, which in this case is globals.

Thanks, but hey, contradiction: you mention globals as an "enclosing" scope, 
i.e. that a module can have a scope, while stating that only classes and 
functions have their own scope (so, would a module have it's not own scope?).

I think, having now read up and down and sideways in the docs, that the proper 
term in Python is "namespace", and that "scope" in Python refers to where the 
names in a namespace are directly accessible, with a special case for classes, 
namely that the scope of a class' namespace doesn't penetrate down into function 
definitions, hence problem with comprehensions expressed directly in a class 
definition. I believe that's a so called language "wart"  --  which C++ is full 
of, just now discovering some of Python's :-). It's almost like C++'s "most 
vexing parse", a natural and apparently meaningful source code construct that 
due to the detailed rules turns out to be meaningless. I wish language designers 
could be a little less hooked on low level consistency. Because it makes for 
high level inconsistency, very difficult to explain without zillions of details.

But anyways, it's starting to make more sense, yes.


Cheers,

- Alf



More information about the Python-list mailing list