This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Danh
Recipients Danh, MLModel, georg.brandl
Date 2010-04-15.12:17:44
SpamBayes Score 1.3436605e-08
Marked as misclassified No
Message-id <1271333867.02.0.872606724516.issue5419@psf.upfronthosting.co.za>
In-reply-to
Content
I got struck by the same feature. In addition, currently the docs are wrong in the examples (at http://docs.python.org/dev/py3k/library/urllib.request.html#examples the output of f.read() is a string instead of bytes). There I propose the change from 

>>> import urllib.request
>>> f = urllib.request.urlopen('http://www.python.org/')
>>> print(f.read(100))
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?xml-stylesheet href="./css/ht2html

to

>>> import urllib.request
>>> f = urllib.request.urlopen('http://www.python.org/')
>>> print(f.read(100).decode('utf-8'))
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm

The other examples need to be corrected in a similar way.
Even more importantly, the "HOWTO Fetch Internet Resources Using The urllib Package" needs to be corrected too.

In the documentation of urllib.request.urlopen I propose to add a sentence (after the paragraph "This function returns a file-like object...") explaining that reading the object returns bytes that need to be decoded to a string:
"Note that the method read() returns bytes that need to be decoded to a string using decode()."
History
Date User Action Args
2010-04-15 12:17:47Danhsetrecipients: + Danh, georg.brandl, MLModel
2010-04-15 12:17:47Danhsetmessageid: <1271333867.02.0.872606724516.issue5419@psf.upfronthosting.co.za>
2010-04-15 12:17:45Danhlinkissue5419 messages
2010-04-15 12:17:44Danhcreate