Python 3.2 question
Asked Answered
S

4

9

I am using Python 3.2. I can import "urllib" library just like with 2.x version. But I can'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?

Schism answered 13/5, 2011 at 6:52 Comment(1)
First question -> maybe reading the doc ? Second question -> "The languages, they are A-changin'"Wain
S
9

You should use urllib.request. Example here.

Swafford answered 13/5, 2011 at 7:0 Comment(0)
T
3

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.

Telemechanics answered 13/5, 2011 at 6:57 Comment(0)
L
3

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.

Limnetic answered 13/2, 2012 at 21:13 Comment(0)
M
0

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.

Mordancy answered 13/5, 2011 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.