On Wed, Oct 21, 2009 at 10:56 PM, Mike Krell <mbk.li...@gmail.com> wrote: > Is there any possibility of backporting support for the nonlocal keyword > into a 2.x release? I see it's not in 2.6, but I don't know if that was an > intentional design choice or due to a lack of demand / round tuits. I'm > also not sure if this would fall under the scope of the proposed moratorium > on new language features (although my first impression was that it could be > allowed since it already exists in python 3. > > One of my motivations for asking is a recent blog post by Fernando Perez of > IPython fame that describes an interesting decorator-based idiom inspired by > Apple's Grand Central Dispatch which would allow many interesting > possibilities for expressing parallelization and other manipulations of > execution context for blocks of python code. Unfortunately, using the > technique to its fullest extent requires the nonlocal keyword. > > The blog post is here: > https://cirl.berkeley.edu/fperez/py4science/decorators.html >
Just as a note, the nonlocal there is not a requirement... You can just create a mutable object there and change that object (so, you don't need to actually rebind the object in the outer scope). E.g.: instead of creating a float in the context, create a list with a single float and change the float in the list (maybe the nonlocal would be nicer, but it's certainly still usable) Cheers, Fabio _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com