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@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
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to