Created
May 5, 2015 16:24
-
-
Save jonEbird/20042995d2d031b7b6b3 to your computer and use it in GitHub Desktop.
Python context manager to temporarily disable stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
@contextmanager | |
def stderr_off(): | |
import sys | |
stderr_orig = sys.stderr | |
sys.stderr = open('/dev/null', 'w') | |
yield | |
sys.stderr = stderr_orig | |
# ...later on... | |
with stderr_off(): | |
events = my_calendar.list_events( | |
start=local_tz.localize(this_morning).astimezone(pytz.utc), | |
end=local_tz.localize(this_evening).astimezone(pytz.utc), | |
details=True | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment