title: nested classes in Python
body: <p>
  Dealing with classes (nested etc) does not look easy in <strong>Python</strong>, <strong>surprisingly</strong>! The following problem appeared to me recently and took several hours (try, search ...) without success. I read most of SO related links but none of them has pointed the issue presented here! </p>
  
  <pre>
  #------------------------------------
  class A:
      def __init__(self):
          self.a = 'a'
          print self.a
  
  class B(A):
      def __init__(self):
          self.b = 'b'
          A.a = 'a_b'
          print self.b, A.a
  #------------------------------------
  class C:
      class A:
          def __init__(self):
              self.a = 'a'
              print self.a
  
      class B(A):
          def __init__(self):
              self.b = 'b'
              A.a = 'a_b'
              print self.b, A.a
  #------------------------------------
  #------------------------------------
  >>> c1 = A()
  a
  >>> c1.a
  'a'
  >>> c2 = B()
  b 
  >>> c2.a, c2.b
  ('a_b', 'b')
  >>> c3 = C()
  >>> c4 = c3.A()
  a
  >>> c4.a
  'a'
  >>> c5 = c3.B()
  b a_b
  >>> c5.b
  'b'
  >>> c5.a
  Traceback (most recent call last):
    File "", line 1, in 
  AttributeError: B instance has no attribute 'a'
  </pre>
  
  <p>Where is the problem in the code?
  <strong>AND</strong>
  In both cases it seems that when B(A) is initialized A() is not initialized. What is the solution for this issue? Note that the term <code>A.__init__()</code> being called inside B()'s <code>__init__()</code> does not work!</p>
  
  <p><strong>Updates:</strong></p>
  
  <pre>
  class Geometry:
      class Curve:
          def __init__(self,c=1):
              self.c = c                          #curvature parameter
              print 'Curvature %g'%self.c
              pass                                #some codes
  
      class Line(Curve):
          def __init__(self):
              Geometry.Curve.__init__(self,0)     #the key point
              pass                                #some codes
  
  g = Geometry()
  C = g.Curve(0.5)
  L = g.Line()
  </pre>
  
  <p>which results in:</p>
  
  <pre>
  Curvature 0.5
  Curvature 0
  </pre>
  
  <p>what I was looking for.</p>