def run_rep(self, params, rep):
        """ run a single repetition including directory creation, log files, etc. """
        name = params['name']
        fullpath = os.path.join(params['path'], params['name'])
        logname = os.path.join(fullpath, '%i.log'%rep)
        # check if repetition exists and has been completed
        restore = 0
        if os.path.exists(logname):
            logfile = open(logname, 'r')
            lines = logfile.readlines()
            logfile.close()
            
            # if completed, continue loop
            if 'iterations' in params and len(lines) == params['iterations']:
                return False
            # if not completed, check if restore_state is supported
            if not self.restore_supported:
                # not supported, delete repetition and start over
                # print 'restore not supported, deleting %s' % logname
                os.remove(logname)
                restore = 0
            else:
                restore = len(lines)
            
        self.reset(params, rep)
        
        if restore:
            logfile = open(logname, 'a')
            self.restore_state(params, rep, restore)
        else:
            logfile = open(logname, 'w')
            
        # loop through iterations and call iterate
        for it in xrange(restore, params['iterations']):
            dic = self.iterate(params, rep, it)
            if self.restore_supported:
                self.save_state(params, rep, it)
                
            # replace all spaces in keys with underscores
            for k in dic:
                if ' ' in k:
                    newk = k.replace(' ', '_')
                    dic[newk] = dic[k]
                    del dic[k]
                    # issue warning but only once per key
                    if k not in self.key_warning_issued:
                        print "warning: key '%s' contained spaces and was renamed to '%s'"%(k, newk)    
                        self.key_warning_issued.append(k)
                
            # build string from dictionary
            outstr = ' '.join(map(lambda x: (x[0], str(x[1]))%'%s:%s', dic.items()))
            logfile.write(outstr + '\n')
            logfile.flush()
        logfile.close()

        self.finalize(params, rep)
dataset/ETHPy150Open rueckstiess/expsuite/expsuite.py/PyExperimentSuite.run_rep/swapped operands of `%`