Inner Classes: How can I get the outer-class object at construction time?
<p>Consider the following Python (runs in 2.x or 3.x):</p>

<pre><code>class Outer(object):
  pass

  class Inner(object):
    def __init__(self):
      print("Inner.self", self)

o = Outer()
i = o.Inner()
</code></pre>

<p>I want to get my hands on <code>o</code> while inside <code>Inner.__init__()</code>.  But:</p>

<ul>
<li>I don't want <code>o</code> to be an explicit parameter to <code>Inner</code>.</li>
<li>I want <code>O.Inner</code> and <code>o.Inner</code> to be a class object, not something weird like a closure.</li>
</ul>

<p>Can you suggest how I might achieve this?</p>

<p>Right now my best idea is to use thread local storage.  In my use case, whenever I construct an <code>o.Inner()</code>, I'm already inside a method on <code>o</code> somewhere, and it wouldn't be a big deal to add</p>

<pre><code>threading.local()["my o object"] = o
</code></pre>

<p>to my code.</p>

<p>This gives you an idea of the level of depravity I'm willing to consider.</p>
