summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2016-07-26 19:57:23 +0300
committerVille Skyttä <ville.skytta@iki.fi>2016-07-26 19:57:23 +0300
commitc420c44874d07b7383beacfbfcb084dc8be14d68 (patch)
treef181b2742cb49000751ef9741064d42e20258015 /doc
parent99821550d79bb4524f31f153a53a10a069bafccb (diff)
downloadbeautifulsoup4-c420c44874d07b7383beacfbfcb084dc8be14d68.tar.gz
Open/close files with "with"
Diffstat (limited to 'doc')
-rw-r--r--doc/source/index.rst6
1 files changed, 4 insertions, 2 deletions
diff --git a/doc/source/index.rst b/doc/source/index.rst
index 8258e97..a6b2076 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -298,7 +298,8 @@ constructor. You can pass in a string or an open filehandle::
from bs4 import BeautifulSoup
- soup = BeautifulSoup(open("index.html"))
+ with open("index.html") as fp:
+ soup = BeautifulSoup(fp)
soup = BeautifulSoup("<html>data</html>")
@@ -2776,7 +2777,8 @@ you how different parsers handle the document, and tell you if you're
missing a parser that Beautiful Soup could be using::
from bs4.diagnose import diagnose
- data = open("bad.html").read()
+ with open("bad.html") as fp:
+ data = fp.read()
diagnose(data)
# Diagnostic running on Beautiful Soup 4.2.0