Re: Weird behavior with lexical scope

2008-11-07 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Terry Reedy wrote: [EMAIL PROTECTED] wrote: class Outer: def __init__(self): class Inner: def __init__(self): pass a = Inner() This create a duplicate Inner class object for every instance of Outer, which is almost certainly not

Weird behavior with lexical scope

2008-11-06 Thread mrstevegross
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

Re: Weird behavior with lexical scope

2008-11-06 Thread Arnaud Delobelle
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

Re: Weird behavior with lexical scope

2008-11-06 Thread mrstevegross
def __init__(self, Inner=Inner): Ok, the Inner=Inner trick works. What the heck does that do, anyway? I've never seen that formulation. --Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: Weird behavior with lexical scope

2008-11-06 Thread skip
def __init__(self, Inner=Inner): Steve Ok, the Inner=Inner trick works. What the heck does that do, anyway? Steve I've never seen that formulation. Understanding that will put you on the path to scoping enlightenment. Consider when that default assignment is established and how that

Re: Weird behavior with lexical scope

2008-11-06 Thread Kirk Strauser
At 2008-11-06T16:57:39Z, mrstevegross [EMAIL PROTECTED] writes: class Outer: class Inner: def __init__(self): pass def __init__ (self): a = Inner() Outer() Try instead: class Outer: def __init__(self): a = self.Inner() -- Kirk Strauser The Day Companies

Re: Weird behavior with lexical scope

2008-11-06 Thread [EMAIL PROTECTED]
On Nov 6, 9:57 pm, mrstevegross [EMAIL PROTECTED] wrote: 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

Re: Weird behavior with lexical scope

2008-11-06 Thread Terry Reedy
[EMAIL PROTECTED] wrote: On Nov 6, 9:57 pm, mrstevegross [EMAIL PROTECTED] wrote: 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