Context manager for temporarily redirecting stdout to another file. # How to send help() to stderr with redirect_stdout(sys.stderr): help(dir) # How to write help() to a file with open('help.txt', 'w') as f: with redirect_stdout(f):
| 409 | |
| 410 | |
| 411 | class redirect_stdout(_RedirectStream): |
| 412 | """Context manager for temporarily redirecting stdout to another file. |
| 413 | |
| 414 | # How to send help() to stderr |
| 415 | with redirect_stdout(sys.stderr): |
| 416 | help(dir) |
| 417 | |
| 418 | # How to write help() to a file |
| 419 | with open('help.txt', 'w') as f: |
| 420 | with redirect_stdout(f): |
| 421 | help(pow) |
| 422 | """ |
| 423 | |
| 424 | _stream = "stdout" |
| 425 | |
| 426 | |
| 427 | class redirect_stderr(_RedirectStream): |
no outgoing calls
searching dependent graphs…