import sys
import os
class Logger(object):
def __init__(self, fileN="default.log"):
self.terminal = sys.stdout
self.log = open(fileN, "a")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
pass
# print 前调用
sys.stdout = Logger('datalog.txt')