mrstevegross <[EMAIL PROTECTED]> writes: > I ran into a weird behavior with lexical scope in Python. I'm hoping > someone on this forum can explain it to me. > > Here's the situation: I have an Outer class. In the Outer class, I > define a nested class 'Inner' with a simple constructor. Outer's > constructor creates an instance of Inner. The code looks like this: > > ========= > class Outer: > class Inner: > def __init__(self): > pass > def __init__ (self): > a = Inner() > Outer() > ========= > > However, the above code doesn't work. The creation of Inner() fails.
This is because there isn't lexical scoping in class scopes. Try replacing a = Inner() with a = Outer.Inner() Alternatively, class Outer: class Inner: ... def __init__(self, Inner=Inner): a = Inner() HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list