code: def save_namespace(self, filename):
          
          from spyder_kernels.utils.nsview import get_remote_data
          from spyder_kernels.utils.iofuncs import iofunctions
  
          ns = self._get_current_namespace()
          settings = self.namespace_view_settings
          data = get_remote_data(ns, settings, mode='picklable',
                                 more_excluded_names=EXCLUDED_NAMES).copy()
          return iofunctions.save(data, filename)
docs: Save namespace into filename