[Tutor] python2 vs python3 urllib

pierre dagenais eq742 at ncf.ca
Mon Apr 25 03:14:52 CEST 2011


On 11-04-23 06:58 PM, pierre dagenais wrote:
> The following code works as expected with python version 2.6.5, but 
> with version 3.1.2 I get the following error:
>
> pierre:/MyCode/mesProjets$ py3 test.py
>
> Traceback (most recent call last):
> File "test.py", line 3, in <module>
> sock = urllib.urlopen("http://diveintopython.org/")
> AttributeError: 'module' object has no attribute 'urlopen'
>
>
>
>
> The code:
>
> #example 8.5 of diveintopython.org/
> import urllib
> sock = urllib.urlopen("http://diveintopython.org/")
> htmlSource = sock.read()
> sock.close()
> print (htmlSource)
>
> What is the proper syntax in version 3?
>
> Thank you,
> Your help is much appreciated.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
Thank you everybody,

The short answer was of course:
import urllib.request
instead of :
import urllib

I realize I'm still confused about packages, libraries, modules, 
classes, etc...
Right now they're all more or less the same to me. I've got some reading 
to do.
Thanks again,

Pierre


More information about the Tutor mailing list