python: module has no attribute mechanize

你离开我真会死。 提交于 2019-12-22 11:13:05

问题


#!/usr/bin/env python
import mechanize

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

Gives:

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'

And I'm confused. I have the module installed for 2.6 and 2.7, same result...


回答1:


Change your filename away from mechanize.py. Python is importing your file as the module.



来源:https://stackoverflow.com/questions/4236365/python-module-has-no-attribute-mechanize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!