[Python-Dev] Explicit Lexical Scoping (pre-PEP?) (original) (raw)
Just van Rossum just at letterror.com
Wed Jul 5 16:16:15 CEST 2006
- Previous message: [Python-Dev] Explicit Lexical Scoping (pre-PEP?)
- Next message: [Python-Dev] Explicit Lexical Scoping (pre-PEP?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Simon Percivall wrote:
On 5 jul 2006, at 11.40, Scott Dial wrote: > Guido van Rossum wrote: >> Would this also use ..num to refer to num in an outer scope two >> levels removed? > > I realize this was a wink, but it is a valid problem with the > "dot"-proposal. > > def foo(n): > def bar(n): > def baz(): > return .n > > So, which 'n' outer 'n' is being referenced? Seems like you need to > either be able to do multiple dots (ugly, hard to read) or only do a > single-step outwards reference. But then that has it's own > problems, if > I meant the 'n' passed into 'foo', then I have to resort to such > nonsense as:
No, it's actually not a problem. foo()'s "n" should just be hidden. If you don't want it to be hidden, don't write your function that way. If you find you need deeply nested functions where local names shadow names in outer scopes that you need to access you might want to think of another way to solve your problem.
+1, YAGNI.
Just
- Previous message: [Python-Dev] Explicit Lexical Scoping (pre-PEP?)
- Next message: [Python-Dev] Explicit Lexical Scoping (pre-PEP?)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]