What does defining a function with in the __init__ constructor in python mean?
<p>I have just seen the following code and would like to know what the function within the 
<code>__init__</code> function means</p>

<pre><code>def __init__(self):
    def program(percept):
        return raw_input('Percept=%s; action? ' % percept)
    self.program = program
    self.alive = True
</code></pre>

<p>This code</p>

<pre><code>class Foo:
    def __init__(self):
        def program(percept): 
            return raw_input('Percept=%s; action? ' % percept)
        self.program = program
</code></pre>

<p>AFAIK, is actually the exact same as this since <code>self.program = program</code>. </p>

<pre><code>class Foo:
    def __init__(self):
        pass

    def program(self, percept): 
        return raw_input('Percept=%s; action? ' % percept)
</code></pre>

<p>The only reason I can see to nest a function there was if you just used the function to do some initializations within the constructor, but didn't want to expose it on the class. </p>

python constructor init