0
1

More than 3 years have passed since last update.

contextlib.redirect_stdoutとcontextlib.redirect_stderr

Posted at

ファイルに書き込みます

import contextlib
import logging
import sys

# x = input('Enter:')
# print(x)

with open('stdout.log', 'w') as f:
    with contextlib.redirect_stdout(f):
        print('hello')


with open('stderr.log', 'w') as f:
    with contextlib.redirect_stderr(f):
        logging.error('Error!')
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1