标签:save utf-8 file print pen std pytho with open port
# -*- 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 #恢复标准输出流
标签:save utf-8 file print pen std pytho with open port
原文地址:https://www.cnblogs.com/hui-code/p/12716903.html