previousTStamp = strftime("%B %a %d", localtime()) command_log = open('%s.log'%(previousTStamp),'a+') def TStamp(self, txt): currentTStamp = strftime("%B %a %d", localtime()) if currentTStamp is not previousTStamp: self.command_log.close() self.command_log = open('%s.log'%(currentTStamp),'a+) stamp = strftime("%H %M", localtime()) logText = '%s : %s\n'%(stamp, txt) self.command_log.write(logText) self.command_log.flush() print logText