2010-11-21 74 views
3
#!/usr/bin/env python 
import mechanize 

mech = mechanize.Browser() 
page = br.open(SchoolRank('KY')) 

给出:蟒蛇:模块没有属性机械化

Traceback (most recent call last): 
    File "mechanize.py", line 2, in <module> 
    import mechanize 
    File "/home/jcress/Documents/programming/schooldig/trunk/mechanize.py", line 12, in <module> 
    mech = mechanize.Browser() 
AttributeError: 'module' object has no attribute 'Browser' 

而且我很困惑。我为2.6和2.7安装了模块,结果相同...

回答

18

将您的文件名从mechanize.py中移开。 Python正在导入您的文件作为模块。

+1

哈哈哈。我很聪明。 – 2010-11-21 04:04:18

+4

感谢您的支持,但我仍然陷入僵局,直到我意识到必须删除相应的.pyc文件 – 2012-08-14 11:34:41