On 04 Nov 2005 11:04:58 +0100, Stefan Arentz <[EMAIL PROTECTED]> wrote:
>Antoon Pardon <[EMAIL PROTECTED]> writes: > >> Op 2005-11-03, Mike Meyer schreef <[EMAIL PROTECTED]>: >> > Antoon Pardon <[EMAIL PROTECTED]> writes: >> >>> What would you expect to get if you wrote b.a = b.a + 2? >> >> I would expect a result consistent with the fact that both times >> >> b.a would refer to the same object. >> > >> > Except they *don't*. This happens in any language that resolves >> > references at run time. >> >> Python doesn't resolve references at run time. If it did the following >> should work. >> >> a = 1 >> def f(): >> a = a + 1 >> >> f() > >No that has nothing to do with resolving things at runtime. Your example >does not work because the language is very specific about looking up >global variables. Your programming error, not Python's shortcoming. > If someone has an old version of Python handy, I suspect that it used to "work", and the "a" on the right hand side was the global "a" because a local "a" hadn't been defined until the assignment, which worked to produce a local binding of "a". Personally, I like that better than the current way, because it follows the order of accesses implied by the precedences in expression evaluation and statement execution. But maybe I don't RC ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list