Python inheritance weirdness depending on how the subclass is called
<p>I am getting an error when I call a subclass from another class, but not when I call it directly. It seems that when I create an instance of this subclass from a different class the information in the superclass is not getting passed to the subclass.</p>

<pre><code>class HBatom(object):
    def __init__(self, struct, sele, **kwargs):
        self.struct = struct
        self.sele = sele

class HDonor(HBatom):
    def __init__(self,struct,sele,**kwargs):
        super(HDonor,self).__init__(struct,sele,**kwargs)
        self.find_H()
    def find_H(self):
        bonded = self.struct.select(''.join(["bonded to ", self.sele.getSelstr()]))
</code></pre>

<p>This works</p>

<pre><code>import HBonds
HB = HBonds.HDonor(structure,Nsel,f_wat=1)
</code></pre>

<p>But when I create an instance of a class that contains a dictionary of HDonors and then tell it to populate I get an error</p>

<pre><code>HN = HBonds.HNtwrk(structure,1)
HN.build_HNtwrk()

AttributeError: 'HDonor' object has no attribute 'sele'
</code></pre>

<p>Executing with pdb shows me that in the second case <em>self</em> contains no attributes of the HBatom parent class. How is it possible for <em>self</em> to contain that info in the first case but not in the second?</p>

<p>Sorry, I didn't include HNtwrk in the original post. The total code is almost 400 lines, so I don't want to include more than necessary. Here are the relevant parts of HNtwrk</p>

<pre><code>class HNtwrk:
  def __init__(self,structure, f_wat = 0):
    self.f_wat = f_wat
    self.struct = structure
    self.rh_o = 2.5
    self.rn_o = 3.5
    self.Dons = dict()
    self.Accs = dict()

def build_HNtwrk(self):
    Dsele = self.struct.select(DonStr)
    Asele = self.struct.select(AccStr)
    self.addDons(Dsele)
    self.addAccs(Asele)

def addDons(self, Dsele):
    for pairs in iterNeighbors(Dsele,self.rn_o,Asele):
        iN = pairs[0].getIndices()[0]
        iA = pairs[1].getIndices()[0]

        if iN not in self.Dons:
            Hdon = HDonor(self.struct,pairs[0].getSelstr,f_wat=self.f_wat)
            self.Dons[iN] = Hdon
</code></pre>

<p>The code trips when I set Hdon because HDonor.find_H() requires HBatom attributes. It is as if HBatom.__init__() is not called during the HDonor init when an HDonor instance is created from HNtwrk. Just to be clear, HNtwrk appears in the same file as the other classes.</p>
