summaryrefslogtreecommitdiff
path: root/doc/source
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2016-07-26 21:27:28 -0400
committerLeonard Richardson <leonardr@segfault.org>2016-07-26 21:27:28 -0400
commitd45fdd36c11ccc91f5ea81e2caf4ae71c47a4f33 (patch)
treeb21305bdac96a3b329a5d7b07835163c9fb60e75 /doc/source
parentd728b532db6e6def64b447bd42cf9a8ff698f03a (diff)
parent22a03ad39a926b09ba6b8dc2a33988b80cae77a6 (diff)
Change the way open() is used. Code contributed by Ville Skyttä.
Diffstat (limited to 'doc/source')
-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