Skip to content

Instantly share code, notes, and snippets.

@jonEbird
Created May 5, 2015 16:24
Show Gist options
  • Save jonEbird/20042995d2d031b7b6b3 to your computer and use it in GitHub Desktop.
Save jonEbird/20042995d2d031b7b6b3 to your computer and use it in GitHub Desktop.
Python context manager to temporarily disable stderr
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