>>> import sys
>>> tmp = sys.stdout
>>> sys.stdout=open('log.txt','a')
>>> print('cisco')
>>> print(1,2,3)
>>> sys.stdout.close()
>>> sys.stdout=tmp
>>> print('haha')
haha
>>> print(open('log.txt','rb').read())
b'welcome to haha\r\ncisco\r\n1 2 3\r\n'
>>> print(open('log.txt','r').read())
welcome to haha
cisco
1 2 3
>>>
>>> import sys
>>> tmp = sys.stdout
>>> sys