I'm aware of Python name mangling, but am running into unexpected behavahior while using mutliple inheritence. Take for example:
class A(object):
  def __init__(self):
    self.__foo=1
  def bar(self):
    return self.__foo
class B(object):
  pass
class C(B):
  def __init__(self):
    self.test=1
class D(C,A):
  pass
print D().bar()
which gives the error:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in bar
AttributeError: 'D' object has no attribute '_A__foo'
However, if I change the definition of "D" to:
class D(A,C):
  pass
it works. Output:
1 
Additionally, if I remove all the member variables from class "C", either definition of D work
class C(B):
  pass
class D1(A, C):
  pass
class D2(C, A):
  pass
print D1().bar()
print D2().bar()
Output:
1
1
Can anyone enlighten me as to what is going on here? I would expect any of these class definitions to behave the same.
 
     
    