tags:

views:

97

answers:

3
class a(object):
    class b:
        a='aaa'

print a.b.a#print 'aaa'

b=a()
print b.b.a#print 'aaa'

thanks

A: 

Either ways, you are accessing: "outerclass/object.innerclass/object.member".

Amit
+4  A: 

No.

To create instance variables, you need to explicitly prefix them with self., in the constructor method __init__(self).

In your code, you're simply assigning in the class scope, and those variables can be reached both ways.

unwind
+4  A: 

Running your code and then a.b.a is b.b.a gives the result of True, which indicates that they are, indeed, referring to the same object - the class variable a of inner class b.

Walter