Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples in usage.rst to Python 3 #223

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)