python print 输出重定向

简介

print 重定向的功能,很实用,记录一下

参考链接

https://www.cnblogs.com/marsggbo/p/10293484.html

code

import sys
import os
np.set_printoptions(threshold=np.inf)
class Logger(object):
def init(self, filename="log.txt"):
self.terminal = sys.stdout
self.log = open(filename, "a+")

def write(self, message):
    self.terminal.write(message)
    self.log.write(message)

def flush(self):
    pass

path = os.path.abspath(os.path.dirname(file))
type = sys.getfilesystemencoding()
sys.stdout = Logger()

猜你喜欢

转载自www.cnblogs.com/eat-too-much/p/12742902.html