a newbie question

Peter Otten __peter__ at web.de
Sun Apr 12 17:01:14 CEST 2009


zhangle2002 at gmail.com wrote:

> I am just learning Python and get a problem when trying this example:
> 
> from urllib import urlopen
> doc=urlopen("http://www.python.org").read()
> print(doc)
> 
> when i run this, i was tould that 'cannot import name "urlopen"
> 
> 
> What's wrong with this code? Do i need to place my code in some
> specific directory? Thanks a lot. '

This function has been moved in Python 3.0. Change your import to

from urllib.request import urlopen

If you are learning with a book using Python 2.x consider switching to
Python 2.5 or 2.6 to try out the examples.

Peter



More information about the Python-list mailing list