title: Is there a benefit to defining a class inside another class in Python?
body: <p>What I'm talking about here are nested classes. Essentially, I have two classes that I'm modeling. A DownloadManager class and a DownloadThread class. The obvious OOP concept here is composition. However, composition doesn't necessarily mean nesting, right?</p>
  
  <p>I have code that looks something like this:</p>
  
  <pre><code>class DownloadThread:
      def foo(self):
          pass
  
  class DownloadManager():
      def __init__(self):
          dwld_threads = []
      def create_new_thread():
          dwld_threads.append(DownloadThread())
  </code></pre>
  
  <p>But now I'm wondering if there's a situation where nesting would be better. Something like:</p>
  
  <pre><code>class DownloadManager():
      class DownloadThread:
          def foo(self):
              pass
      def __init__(self):
          dwld_threads = []
      def create_new_thread():
          dwld_threads.append(DownloadManager.DownloadThread())
  </code></pre>