On Wed, 5 Oct 2016 04:12 am, Rustom Mody wrote: > On Tuesday, October 4, 2016 at 10:06:00 PM UTC+5:30, Steve D'Aprano wrote: >> On Tue, 4 Oct 2016 09:32 pm, Rustom Mody wrote: >> >> > Are not the contents of the scope and the shape of the scope different >> > things? >> >> >> What does "the shape of the scope" mean? >> >> Scopes don't have a shape -- they aren't geometric objects. So I'm afraid >> I don't understand what distinction you are trying to make. > > Ok I was speaking quasi metaphorically > If you have some non-metaphors please tell!
I think that by "shape" of the scope, you mean "some identifier or description which identifies the scope" -- e.g. "globals", "builtins", function foo, function bar, etc. > Take the basic 'content': > x = 1 > y = 2 > z = 3 > > A. Occuring exactly as above at module level > B. Occuring exactly as above inside a function > C. Occuring thus > x = 1 > foo(2,3) > > def foo(y,z): > ... > > D. > def foo(): > x = 1 > def bar(): > y, z = 2,3 > ... > > E. > def foo(): > x = 1 > bar(2,3) > ... > > def bar(y,z): > ... > > > In A,B,C,D,E at some point there's x,y,z having values (contents) 1,2,3 > How do you distinguish them? By which variables (name bindings) exist in which scopes. A: all three names 'x', 'y' and 'z' exist in the module scope, i.e. are globals. B: all three names 'x', 'y' and 'z' exist in some (unknown) local function scope. C: 'x' is a global, 'y' and 'z' are locals of foo. D: 'x' is a local of foo, 'y' and 'z' are locals of bar, where bar is nested within foo. E: 'x' is a local of foo, 'y' and 'z' are locals of bar, where foo and bar exist in the same (global) scope. Since the functions (unknown), foo, bar and other bar are themselves names, to distinguish them you need to know which scope they come from. One of the bars comes from foo's local namespace, the others are globals. > I call it the shape of the scope (or environment or bindings or namespace > or ...???) > > You have a better descriptor for the idea? The name of the scope. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list