简介
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()
---------------------------我的天空里没有太阳,总是黑夜,但并不暗,因为有东西代替了太阳。虽然没有太阳那么明亮,但对我来说已经足够。凭借着这份光,我便能把黑夜当成白天。我从来就没有太阳,所以不怕失去。
--------《白夜行》