Why nested scope rules do not apply to inner Class?
Salim Fadhley
salimfadhley at gmail.com
Tue Aug 12 07:12:27 EDT 2008
> I'm wondering as well if the new nonlocal statement will fix that in py3k?
The "class C3" statement is executing before the "class B" statement
has concluded, so at that time B does not exist in any scope at all,
not even globals(). You could reference B.C1 inside a method because a
method is executed AFTER the class is defined.
class A(object):
pass
class B(object):
class C1(object):
pass
class C2(C1):
foo = A
class C3(object):
@staticmethod
def test( ):
print repr( B.C1 )
print repr( B.C2 )
B.C3.test()
:-)
More information about the Python-list
mailing list