Nested scopes hitch

Jeff Shannon jeff at ccvcorp.com
Mon Apr 8 18:38:15 EDT 2002


In article <1018304015.46066 at cswreg.cos.agilent.com>, 
weeks at vitus.scs.agilent.com says...
> Jeremy Hylton (jeremy at alum.mit.edu) wrote:
> : > Anyway, it increased visibility enough so that it is no longer possible to
> : > call a function and pass it the scope as two dictionaries, which I had 
> : > found handy on occasion.
> 
> : I'm not sure I follow the details here, but I don't see how the change
> : in the scope rules would affect a function unless it specifically
> : exploited nested scopes.  If you wrote a function that only uses
> : locals and globals, can you not call it just the way you always did?
> 
> Yes, the function continues to work.  But the documentation changes.
> Originally, calling the function with the arguments globals() and locals()
> passed to the function all the variable bindings visible at the point where
> the function was called.  That is a tidy concept, and I'm sorry to lose it.

The thought of anyone *expecting* that behavior is shocking and 
frightening to me.  For one thing, it violates the whole point of 
scoping.  Besides which, if you read your documentation 
carefully, the dictionary returned by locals(), at least, is not 
guaranteed to allow write-access.

If you want access to variables inside of a function, you should 
pass those specific variables as arguments.  If you've got lots 
of arguments in common between lots of functions, assemble the 
lot into a class.  If neither of these is appropriate, then you 
should redesign -- you're using a very ugly approach.

-- 

Jeff Shannon
Technician/Programmer
Credit International



More information about the Python-list mailing list