Skip to main content
Commonmark migration
Source Link

Is it possible to temporarily redirect stdout/stderr in Python (i.e. for the duration of a method)?

###Edit:

Edit:

The problem with the current solutions (which I at first remembered but then forgot) is that they don't redirect; rather, they just replace the streams in their entirety. Hence, if a method has a local copy of one the variable for any reason (e.g. because the stream was passed as a parameter to something), it won't work.

Any solutions?

Is it possible to temporarily redirect stdout/stderr in Python (i.e. for the duration of a method)?

###Edit:

The problem with the current solutions (which I at first remembered but then forgot) is that they don't redirect; rather, they just replace the streams in their entirety. Hence, if a method has a local copy of one the variable for any reason (e.g. because the stream was passed as a parameter to something), it won't work.

Any solutions?

Is it possible to temporarily redirect stdout/stderr in Python (i.e. for the duration of a method)?

Edit:

The problem with the current solutions (which I at first remembered but then forgot) is that they don't redirect; rather, they just replace the streams in their entirety. Hence, if a method has a local copy of one the variable for any reason (e.g. because the stream was passed as a parameter to something), it won't work.

Any solutions?

edited title
Link
user541686
  • 212.5k
  • 133
  • 563
  • 935

Python: Temporarily Redirect stdout/stderr

Rollback to Revision 2
Source Link
user541686
  • 212.5k
  • 133
  • 563
  • 935

Python: Temporarily redirectRedirect stdout/stderr

Is it possible to temporarily redirect stdout/stderr in Python (i.e. for the duration of a method)?

Also###Edit:

The problem with the current solutions (which I at first remembered but then forgot) is that they don't redirect; rather, it must workthey just replace the streams in their entirety. Hence, if a method has a local copylocal copy of one the variable for any reason (e.g. because the stream was passed as a parameter to something), it won't work.

Any solutions?

Temporarily redirect stdout/stderr

Is it possible to temporarily redirect stdout/stderr in Python (i.e. for the duration of a method)?

Also, it must work if a method has a local copy of one the variable for any reason (e.g. because the stream was passed as a parameter).

Python: Temporarily Redirect stdout/stderr

Is it possible to temporarily redirect stdout/stderr in Python (i.e. for the duration of a method)?

###Edit:

The problem with the current solutions (which I at first remembered but then forgot) is that they don't redirect; rather, they just replace the streams in their entirety. Hence, if a method has a local copy of one the variable for any reason (e.g. because the stream was passed as a parameter to something), it won't work.

Any solutions?

Removed meta-content, refactored awkward "edit" heading, removed tag from title.
Source Link
user212218
user212218
Loading
added 299 characters in body
Source Link
user541686
  • 212.5k
  • 133
  • 563
  • 935
Loading
Source Link
user541686
  • 212.5k
  • 133
  • 563
  • 935
Loading