Skip to content

Instantly share code, notes, and snippets.

@rloqvist
Created October 31, 2018 13:40
Show Gist options
  • Select an option

  • Save rloqvist/5990092342de1c8aa1e013d8e88eb4dc to your computer and use it in GitHub Desktop.

Select an option

Save rloqvist/5990092342de1c8aa1e013d8e88eb4dc to your computer and use it in GitHub Desktop.
python /dev/null context
import sys
import os
class DevNull:
def __init__(self):
self.out = sys.stdout
def __enter__(self):
self.devnull = open(os.devnull, 'w')
sys.stdout = self.devnull
def __exit__(self, type, value, traceback):
sys.stdout = self.out
self.devnull.close()
from bs4 import BeautifulSoup as bs
from devnull import DevNull
with DevNull():
import requests
url = 'http://example.com'
result = requests.get(url)
soup = bs(result.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment