title: How can I separate the functions of a class into multiple files?
body: <p>I have a main class that has a <em>ton</em> of different functions in it. It's getting hard to manage. I'd like to be able to separate those functions into a separate file, but I'm finding it hard to come up with a good way to do so.</p>
  <p>Here's what I've done so far:</p>
  <h3>File <em>main.py</em></h3>
  <pre><code>import separate
  
  class MainClass(object):
      self.global_var_1 = ...
      self.global_var_2 = ...
  
      def func_1(self, x, y):
          ...
      def func_2(self, z):
          ...
      # tons of similar functions, and then the ones I moved out:
  
      def long_func_1(self, a, b):
          return separate.long_func_1(self, a, b)
  </code></pre>
  <h3>File <em>separate.py</em></h3>
  <pre><code>def long_func_1(obj, a, b):
      if obj.global_var_1:
          ...
      obj.func_2(z)
      ...
      return ...
  # Lots of other similar functions that use info from MainClass
  </code></pre>
  <p>I do this because if I do:</p>
  <p><code>obj_1 = MainClass()</code></p>
  <p>I want to be able to do:</p>
  <p><code>obj_1.long_func_1(a, b)</code></p>
  <p>instead of:</p>
  <p><code>separate.long_func_1(obj_1, a, b)</code></p>
  <p>I know this seems kind of nit-picky, but I want just about all of the code to start with <code>obj_1.</code>, so there isn't confusion.</p>
  <p>Is there a better solution that what I'm currently doing? The only issues that I have with my current setup are:</p>
  <ol>
  <li>I have to change arguments for both instances of the function</li>
  <li>It seems needlessly repetitive</li>
  </ol>
  <p><sub>I know this has been asked a couple of times, but I couldn't quite understand the previous answers and/or I don't think the solution quite represents what I'm shooting for. I'm still pretty new to Python, so I'm having a tough time figuring this out.</sub></p>