[Python-Dev] Explicit Lexical Scoping (pre-PEP?)

Fuzzyman fuzzyman at voidspace.org.uk
Tue Jul 11 10:14:22 CEST 2006


Talin wrote:

>Ka-Ping Yee wrote:
>  
>
>>On Mon, 10 Jul 2006 skip at pobox.com wrote:
>>
>>    
>>
>>>I think Talin's got a point though.  It seems hard to find one short English
>>>word that captures the essence of the desired behavior.  None of the words
>>>in his list seem strongly suggestive of the meaning to me.  I suspect that
>>>means one's ultimately as good (or as bad) as the rest.
>>>      
>>>
>>What's wrong with "nonlocal"?  I don't think i've seen an argument
>>against that one so far (from Talin or others).
>>    
>>
>
>Well, I just think that a fix for "an aesthetic wart" should be, well, 
>aesthetic :)
>
>I also think that it won't be a complete disaster if we do nothing at 
>all - there *are* existing ways to deal with this problem; there are 
>even some which aren't hackish and non-obvious. For example, its easy 
>enough to create an object which acts as an artificial scope:
>
>    def x():
>       scope = object()
>       scope.x = 1
>       def y():
>          scope.x = 2
>
>To my mind, the above code looks about as elegant and efficient as most 
>of the proposals put forward so far, and it already works.
>
>How much are we really saving here by building this feature into the 
>language?
>  
>
 >>> def x():
  ...:    scope = object()
  ...:    scope.x = 1
  ...:    def y():
  ...:        scope.x = 2
>>> x()
---------------------------------------------------------------------------
exceptions.AttributeError                            Traceback (most
recent call
 last)<ipython console>

I've often found it a nuisance that you can't instantiate an 'object',
to use as a mutable 'namespace', but instead have to define an arbitrary
empty class.

What happened to the 'namespace' proposal ?

Michael Foord
http://www.voidspace.org.uk/python/index.shtml

>-- Talin
>_______________________________________________
>Python-Dev mailing list
>Python-Dev at python.org
>http://mail.python.org/mailman/listinfo/python-dev
>Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
>
>  
>



More information about the Python-Dev mailing list