Notice
Recent Posts
Recent Comments
Link
아미(아름다운미소)
[python]print를 로그파일로 생성하기 본문
python print를 로그파일로 생성하기
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 "Test log" # Only on stdout f.close()
'랭귀지 > python' 카테고리의 다른 글
[python] pyqt5 QTableWidget (0) | 2018.11.23 |
---|---|
python 파일 복사 (0) | 2018.11.21 |
[PYTHON] exit 함수 : 프로그램 종료하기 (0) | 2018.11.17 |
pyQt5 QLineEdit 패스워드설정 (0) | 2018.11.16 |
python 숫자 출력에서 천(1000) 단위마다 콤마를 출력 (0) | 2018.11.15 |
Comments