다음 코드 스 니펫이 도움이 될 것이라고 생각합니다. 일부 파일을 가리 키기 위해 단순히 stdout을 변경하려고합니다. 그 후에 출력이 무엇이든 그 파일에 기록됩니다.
나중에 표준 출력을 원래 형식으로 다시 변경합니다.
import sys
# Holding the original output object. i.e. console out
orig_stdout = sys.stdout
# Opening the file to write file deletion logs.
f = open('file.txt', 'a+')
# Changing standard out to file out.
sys.stdout = f
# Any print call in this function will get written into the file.
myFunc(params)
# This will write to the file.
print("xyz")
# Closing the file.
f.close()
# replacing the original output format to stdout.
sys.stdout = orig_stdout
# This will print onto the console.
print("xyz")
평소처럼 파일에 쓰기 만 하시겠습니까? – erip
'with open ('twitter_stream.txt', 'w') f : 스트림의 줄 : print (line, file = f)' – erip