<div class="im">The difference lies in the fact that in C, object references are</div>non-local by default - you have to declare them explicitly in the<br>current scope to make them local.<br><br>Accordingly, I find the idea of a new function-like construct where all<br>

non-argument variable references are nonlocal by default to be a<br>potentially interesting one.<br></blockquote><div><br></div><div>Hmm. That's an interesting idea.</div><div><br></div><div>I don't know enough about internals. It might be possible to do this with a decorator</div>

<div><br></div><div>However, even if possible, that would make everything nonlocal with no way to pick which ones. Here's another idea:</div><div><br></div><div>def foo():</div><div> a = 1</div><div> b = 3</div>

<div> nonlocal def bar():</div><div> local b</div><div> a = 2</div><div> b = 4</div><div> return (a,b)</div><div><br></div><div>foo() => (2, 3)</div><div><br></div><div>Prepending nonlocal to a function definition is equivalent to applying nonlocal to every variable referenced in that function unless the variable is declared local. For backward compatibility, the local statement would only be only recognized inside nonlocal functions. (Thus if you have a function that uses 'local' as a variable it would not need to be changed unless you decided to stick nonlocal in front of it.)</div>