Skip to content

Commit

Permalink
Update examples in usage.rst to Python 3 (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Apr 27, 2021
1 parent 4291399 commit aa47d82
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ a confidence level from ``0`` to ``1``.

.. code:: python
>>> import urllib
>>> rawdata = urllib.urlopen('http://yahoo.co.jp/').read()
>>> import urllib.request
>>> rawdata = urllib.request.urlopen('http://yahoo.co.jp/').read()
>>> import chardet
>>> chardet.detect(rawdata)
{'encoding': 'EUC-JP', 'confidence': 0.99}
Expand Down Expand Up @@ -47,17 +47,17 @@ Example: Detecting encoding incrementally

.. code:: python
import urllib
import urllib.request
from chardet.universaldetector import UniversalDetector
usock = urllib.urlopen('http://yahoo.co.jp/')
usock = urllib.request.urlopen('http://yahoo.co.jp/')
detector = UniversalDetector()
for line in usock.readlines():
detector.feed(line)
if detector.done: break
detector.close()
usock.close()
print detector.result
print(detector.result)
.. code:: python
Expand All @@ -79,10 +79,10 @@ Example: Detecting encodings of multiple files
detector = UniversalDetector()
for filename in glob.glob('*.xml'):
print filename.ljust(60),
print(filename.ljust(60), end='')
detector.reset()
for line in file(filename, 'rb'):
for line in open(filename, 'rb'):
detector.feed(line)
if detector.done: break
detector.close()
print detector.result
print(detector.result)

0 comments on commit aa47d82

Please sign in to comment.