On Sat, 10 Jul 2010 07:06:47 -0700, pcchen wrote: > And for the following three simple lines of code, borrowed from official > python-doc 3.1.2: > >>>>from urllib.request import urlopen >>>>response = urlopen('http://python.org/') html = response.read() > > They could cause this error: > > File "./http.py", line 3, in <module> > from urllib.request import urlopen > File "/usr/local/lib/python3.1/urllib/request.py", line 88, in > <module> > import http.client > File "/home/pcchen/Python/http.py", line 3, in <module> > from urllib.request import urlopen > ImportError: cannot import name urlopen
Look at the traceback: your code executes "from urllib.request import urlopen". That line in turn executes "import http.client". And *that* fails, which causes the first import to fail. It fails because you have shadowed the built-in package http with your own module http.py. Rename your file to something else ("myhttp.py") and it should just work. -- Steven -- http://mail.python.org/mailman/listinfo/python-list