Created
October 31, 2018 13:40
-
-
Save rloqvist/5990092342de1c8aa1e013d8e88eb4dc to your computer and use it in GitHub Desktop.
python /dev/null context
This file contains hidden or 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
| 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() |
This file contains hidden or 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 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