title: Avoid if __name__ == '__main__' in Python subclasses to be run using function from parent
body: <p>I have a generic class (A) which is to be subclassed a lot like this:</p>
  
  <pre><code>class A:
      def run(self):
          ...
          self.do_something()
          ...
  
      #abstract function
      def do_something(self):
          pass
  
  
  class B(A):
      def do_something(self):
          ...
  </code></pre>
  
  <p>The subclasses are in separate files that I'm running directly by adding this code to each file (B is the name of the subclass in the file):</p>
  
  <pre><code>if __name__ == '__main__':
      B().run()
  </code></pre>
  
  <p>My question is, can I avoid having to add this code to all files with the subclasses since the only thing that changes in the code is the class being used (B in the example)?</p>