下午想写个解析网页的程序,从某网站抓点自己想要的东西,查了一下,python的urllib可以给干这种事情。
于是开搞。
写了个程序,起名urllib.py,在里面又import urllib
然后运行的时候,就报
Traceback (most recent call last):
File "./urllib.py", line 3, in
import urllib
File "/home/mt/code/python/urllib.py", line 6, in
u = urllib.urlopen("")
AttributeError: 'module' object has no attribute 'urlopen'
查了一下,在
找到了答案,04年的帖子了。。
This is a name clash. As your script has the same name as the library
module, it imports itself instead of urllib in the library.
To fix it, just rename to, say,
/home/shalen/programming/python/tutorials/py/examineurllib.py
阅读(2215) | 评论(0) | 转发(0) |