python:module没有属性mechanize

jus*_*ess 3 python attributes module mechanize-python

#!/usr/bin/env python
import mechanize

mech = mechanize.Browser()
page = br.open(SchoolRank('KY'))
Run Code Online (Sandbox Code Playgroud)

得到:

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'
Run Code Online (Sandbox Code Playgroud)

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

Mat*_*hen 18

更改您的文件名远离mechanize.py.Python将您的文件导入为模块.

  • 谢谢你,但直到我意识到我必须删除相应的.pyc文件时,我才陷入困境 (4认同)