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 安装了模块,结果相同...

4

1 回答 1

18

将您的文件名从 mechanize.py 中更改出来。Python 正在将您的文件作为模块导入。

于 2010-11-21T04:01:07.477 回答