import sysprint 'Dive in'saveout = sys.stdoutfsock = open('out.log', 'w')sys.stdout = fsockprint 'This message will be logged instead of displayed'sys.stdout = saveoutfsock.close()