[Python-Dev] LOAD_NAME & classes

Tim Peters tim.one@comcast.net
Thu, 25 Apr 2002 01:08:49 -0400

[Guido, on
> x = 2
> def f():
>     print x  # A
>     x = 3
> f()
> print x      # B
> A:  What do you think should happen when the print at A executes?
> B:    "   "  "    "      "      "     "   "    "    " B     "   ?

> That's not a fair experiment until after you've given them a good
> concept of local and global variables without name conflicts.

I think my point is getting lost twice:

1. My suspicion is that the majority of people I've explained this
   to, over the years and years, would have answered the equivalent
   to "well, B should print 3, of course!", when translated to the
   specific context in which their confusion arose.  That is, I suspect
   they didn't understand local variables at all, not they that had
   some vision of "well, it's the global name unless and until I
   dynamically override it with a local name, at which point the
   global name with the same spelling is no longer relevant".

2. If we're talking about people willing to be taught "a good concept
   of local and global variables" before going postal, there's
   no "problem" to be solved here!  I suspect even Mr. Kuchling
   understands how local variables work today <wink>.

> ...
> But on the other hand, it's easy to show that after ...
> which can then be used to explain that variable assignments create
> local variables.
> You don't need to explain the *reason* for this feature at this point ..
> Next you can explain the global statement ...
> After that you can show how name conflicts are handled ...
> At some point you should also point out that ...
> *THEN* you are ready for the experiment Tim proposes above.

Anyone willing to sit through that much explanation will have no problem
understanding how locals work today.  Besides, if you get to tell them
beforehand that "variable assigments *create* local variables" dynamically,
then I get to tell them beforehand that variable assignments don't create
local variables dynamically.  At that point we'd only be testing how
faithfully they can regurgitate what they've just been told.

I'm not a sure a difference between 12% comprehension rate and 13%
comprehension rate is statistically significant anyway <0.9 wink>.