title: pythonic way to customize classes
body: <p>I am trying to figure out a clean way to use inheritance for custom classes. I have the following directory structure.</p>
  
  <pre><code>inheritTest.py
  Level1
      __init__.py
      t_Generic.py
  Level2
      __init__.py
      t_Custom.py
  </code></pre>
  
  <p><strong>Goal:</strong> I want all the classes of t_Generic accessible by importing t_Custom module and allow needed customization in t_Custom.</p>
  
  <p>There is nothing in two of the <strong>init</strong>.py files above. </p>
  
  <p>t_Generic.py contains some generic classes like these:</p>
  
  <pre><code>class A(object):
      def __init__(self):
          self.hello = "Hello! I am Mr.A from t_generic"
      def someOtherMethod(self):
          pass
  
  class B(object):
      def __init__(self):
          self.hello = "Hello! I am Mr.B from t_generic"
      def someOtherMethod(self):
          pass
  
  class C(object):
      def __init__(self):
          self.hello = "Hello! I am Mr.C from t_generic"
      def changeHello(self):
          pass
  </code></pre>
  
  <p>Experimental t_Custom.py is as below:</p>
  
  <pre><code>import Level1.t_Generic
  
  #Override any Generic classes in this module.
  
  #Option 1: Let's get Generic A so it lives in this scope as A
  from Level1.t_Generic import A
  
  #Option 2: Let's create B and inherit from Generic, make future custom changes here
  class B(Level1.t_Generic.B):
      def __init__(self):
          super(B,self).__init__()
  
  
  #I really want to inherit from C and change it's behavior
  class C(Level1.t_Generic.C):
      def __init__(self):
          super(C,self).__init__()
      def changeHello(self):
          self.hello = "Hello! I am Mr.C modified in t_Custom"
  </code></pre>
  
  <p><strong>Question:</strong> What's the pythonic way to do something like this? Should I just import all the generic classes in Custom module as in option 1 or should I create an inherited class in Custom as in Option 2 and modify the ones I want to inherit from?</p>
  
  <p>Example use case in inheritTest.py:</p>
  
  <pre><code>import Level2.t_Custom
  
  a = Level2.t_Custom.A()
  b = Level2.t_Custom.B()
  c = Level2.t_Custom.C()
  
  print a.hello
  print b.hello
  print c.hello
  c.changeHello()
  print c.hello
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Hello! I am Mr.A from t_generic
  Hello! I am Mr.B from t_generic
  Hello! I am Mr.C from t_generic
  Hello! I am Mr.C modified in t_Custom
  </code></pre>