title: Pickle fit-object
body: <p>I wrote a class where some data are fitted. Since the <em>fitting</em> takes very long when lots of data have to be fitted, I want to save the fit-object of this class so I do not have to <strong>repeat</strong> the fitting when I want to use the fitted data later. Using pickle, I get the following error calling the save method on an object:</p>
  
  <pre><code>AttributeError: Can't pickle local object 'ConstantModel.__init__.&lt;locals&gt;.constant'
  </code></pre>
  
  <p>I only have this problem when pickle the fitted data, pickle works if I save the object before fitting.
  Is there a way to pickle fitted data or is there a nice workaround?</p>
  
  <pre><code>class pattern:
      def fitting(self):
          mod_total = lmfit.models.ConstantModel()
          pars_total = mod_total.guess(self.y, x=self.x)
  
          self.fit = mod_total.fit(self.y, pars_total, x=self.x)
  
      def save(self, path):
          with open(path, 'wb') as filehandler: 
              pickle.dump(self, filehandler)
  </code></pre>