code: def write_to_csv(self, filename=None, extension='.dat', overwrite=False,
                       stride=1, chunksize=None, **kw):
          import os
          if not filename:
              assert hasattr(self, 'filenames')
              filenames = []
              for f in self.filenames:
                  base, _ = os.path.splitext(f)
                  filenames.append(base + extension)
          elif isinstance(filename, str):
              filename = filename.replace('{stride}', str(stride))
              filenames = [filename.replace('{itraj}', str(itraj)) for itraj
                           in range(self.number_of_trajectories())]
          else:
              raise TypeError("filename should be str or None")
          self.logger.debug("write_to_csv, filenames=%s" % filenames)
          import errno
          for f in filenames:
              try:
                  st = os.stat(f)
                  raise OSError(errno.EEXIST)
              except OSError as e:
                  if e.errno == errno.EEXIST:
                      if overwrite:
                          continue
                  elif e.errno == errno.ENOENT:
                      continue
                  raise
          f = None
          from pyemma._base.progress import ProgressReporter
          pg = ProgressReporter()
          it = self.iterator(stride, chunk=chunksize, return_trajindex=False)
          pg.register(it.n_chunks, "saving to csv")
          with it, pg.context():
              oldtraj = -1
              for X in it:
                  if oldtraj != it.current_trajindex:
                      if f is not None:
                          f.close()
                      fn = filenames[it.current_trajindex]
                      self.logger.debug("opening file %s for writing csv." % fn)
                      f = open(fn, 'wb')
                      oldtraj = it.current_trajindex
                  np.savetxt(f, X, **kw)
                  f.flush()
                  pg.update(1, 0)
          if f is not None:
              f.close()