Declaring class object datatypes
<p>I have a class <code>Foo</code> which contains a datamember of type <code>Bar</code>. I can't make a generalized, "default" <code>Bar.__init__()</code> - the <code>Bar</code> object is passed into the <code>Foo.__init__()</code> method. </p>

<p>How do I tell Python that I want a datamember of this type? </p>

<pre><code>
class Foo:

# These are the other things I've tried, with their errors    
    myBar         # NameError: name 'myBar' is not defined
    Bar myBar     # Java style: this is invalid Python syntax.
    myBar = None  #Assign "None", assign the real value in __init__. Doesn't work 
#####

    myBar = Bar(0,0,0) # Pass in "default" values. 
    def __init__(self, theBar):
        self.myBar = theBar

    def getBar(self):
        return self.myBar
</code></pre>

<p>This works, when I pass in the "default" values as shown. However, when I call <code>getBar</code>, I do <em>not</em> get back the one I passed in in the <code>Foo.__init__()</code> function - I get the "default" values. </p>

<pre><code>
b = Bar(1,2,3)
f = Foo(b)
print f.getBar().a, f.getBar().b, f.getBar().c
</code></pre>

<p>This spits out <code>0 0 0</code>, <strong>not</strong> <code>1 2 3</code>, like I'm expecting. </p>

<p>If I don't bother declaring the <code>myBar</code> variable, I get errors in the <code>getBar(self):</code> method (<code>Foo instance has no attribute 'myBar'</code>). </p>

<p>What's the correct way to use a custom datamember in my object?</p>
