> > > If a function knows of the presence of a global, it's not asking too > > much for it to not re-use the same name in local scope. > > Yes.
It's just a function wanting to act as-if it were in a different environment than its default. By that same reasoning you could state that "If a function knows of the presence of a built-in, it's not asking too much for it to not re-use the same name in local scope." Yet if rebinding "id" is such a crime, why is it so oft done? Rebinding logger locally in a function is really no different to a subclass rebinding a variable from its main class using that class' value. *The only difference is that, in that case, you have an alternate binding to the original value.* * * >>> class A(): ... val = 1 ... >>> class B(A): ... val = str(val) # Obviously, this doesn't work ... <SNIP> NameError: name 'val' is not defined >>> class B(A): ... val = str(A.val) # But it's OK as we can just do this ^^ ... >>> B().val '1' >>> The only reason it's not minded with classes is because there's a good way to do it. I get that my analogy doesn't use globals, but the idea of extending a more-global attribute locally is shared between the concepts.
-- http://mail.python.org/mailman/listinfo/python-list