J
John Salerno
Here's a sentence from Learning Python:
"Names not assigned a value in the function definition are assumed to be
enclosing scope locals (in an enclosing def), globals (in the enclosing
module's namespace) or built-in (in the predefined __builtin__ names
module Python provides."
I have trouble reading this sentence. First, I don't understand if the
word 'enclosing' is a verb or an adjective. The whole flow of the
sentence seems convoluted.
But my real question is this, which is related to the above:
"Name references search at most four scopes: local, then enclosing
functions (if any), then global, then built-in."
I understand what global and built-in are, and I thought I understood
the concept of local too, but when I got to this sentence (and the
previous sentence), I became confused about the first two scopes. What's
the difference between 'local' and 'enclosing functions'? I thought that
the only way to create a local namespace was if there *was* a function
definition, so now I'm confused by the apparent difference that the
authors are referring to. What's an example of a local scope without
having a function definition? Loops and if statements, perhaps?
And feel free to dissect that first sentence up above, because I just
don't get it.
Thanks.
"Names not assigned a value in the function definition are assumed to be
enclosing scope locals (in an enclosing def), globals (in the enclosing
module's namespace) or built-in (in the predefined __builtin__ names
module Python provides."
I have trouble reading this sentence. First, I don't understand if the
word 'enclosing' is a verb or an adjective. The whole flow of the
sentence seems convoluted.
But my real question is this, which is related to the above:
"Name references search at most four scopes: local, then enclosing
functions (if any), then global, then built-in."
I understand what global and built-in are, and I thought I understood
the concept of local too, but when I got to this sentence (and the
previous sentence), I became confused about the first two scopes. What's
the difference between 'local' and 'enclosing functions'? I thought that
the only way to create a local namespace was if there *was* a function
definition, so now I'm confused by the apparent difference that the
authors are referring to. What's an example of a local scope without
having a function definition? Loops and if statements, perhaps?
And feel free to dissect that first sentence up above, because I just
don't get it.
Thanks.