2010-11-21 73 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