Python 3.2 question
I am using Python 3.2. I can import "urllib" library just like with 2.x version. But I can开发者_Go百科't find methods such as urlopen, urlretrieve, etc. What gives? How do I retrieve a webpage on v3.2?
I have tried to import urllib2 and urllib3 libraries. But my machine says it can't find those modules so not importable. Why these two newest libraries aren't supported in v3.2?
You should use urllib.request
. Example here.
The 2.x docs mention that in Python 3.x, the modules have been split into urllib.request
and urllib.error
. If you have some Python 2.x code and want to convert the modules to 3.x, you may be able to use the 2to3
tool.
It was changed in the newer versions and was split up to now be urllib.request
.
from urllib.request import urlopen
A lot of what you're looking for is in the python library section on urllib.request and someone just mentioned an actual example from the documents that shows how the urllib.request.urlopen can be used.
Python 3000 represents a break with the past. Functions have been cleaned up, syntax has been modified, and the stdlib has been reorganized to provide a more logical grouping of tasks and abilities.
TL;DR: Things change.
精彩评论