import sys
class Tee(object):
def __init__(self, *files):
self.files = files
def write(self, obj):
for f in self.files:
f.write(obj.encode('utf-8'))
if __name__ == "__main__":
f = open('logfile.txt', 'w')
original = sys.stdout
sys.stdout = Tee(sys.stdout, f)
print "test" # This will go to stdout and the file out.txt
#use the original
sys.stdout = original
print "This won't appear on file" # Only on stdout
f.close()
위 코드는 logfile.txt를 만들고 "test"를 그 곳에 출력 (log출력 리다이렉션)합니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 4 | 다른 디렉터리의 파일(모듈) import 하기 | pjk | 2014.08.22 | 8145 |
| 3 |
[PyQt4]윈도우창에 별 찍기 예제
| pjk | 2014.08.19 | 11674 |
| 2 |
Python으로 작성된 프로그램을 윈도우응용프로그램(exe)으로 빌드하기
| pjk | 2014.08.03 | 17132 |
| 1 | 파이썬으로 작성된 소스를 py2exe을 이용하여 윈도우 응용프로그램 빌드시 콘솔창 숨기기 | pjk | 2014.07.29 | 18023 |