首页 > 其他 > 详细

print重定向

时间:2020-04-17 00:18:53      阅读:60      评论:0      收藏:0      [点我收藏+]
# -*- coding: utf-8 -*-
‘‘‘
@File  : test.py
@Author: qiguagnhui
@Date  : 2020-04-11 23:17
@Desc  :
‘‘‘
import os
import sys


savedStdout = sys.stdout  #保存标准输出流
with open(‘out.txt‘, ‘w+‘) as file:
    sys.stdout = file  #标准输出重定向至文件
    content = os.popen(‘pwd; which python‘, ‘r‘).read()
    print(content)

sys.stdout = savedStdout  #恢复标准输出流

print重定向

原文:https://www.cnblogs.com/hui-code/p/12716903.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!