-1

I am using mechanize for the first time. If I type the line from mechanize import Browserin python shell (interpreter) it doesn't give any error but when run the same code as a part of a .py file it gives the following error:

Traceback (most recent call last):
  File "/home/namit/Codes/BS4/mechanize.py", line 1, in <module>
    import mechanize
  File "/home/namit/Codes/BS4/mechanize.py", line 4, in <module>
    mech = mechanize.Browser()
AttributeError: 'module' object has no attribute 'Browser'
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Namit Juneja
  • 498
  • 5
  • 13
  • 1
    possible duplicate of [python: module has no attribute mechanize](http://stackoverflow.com/questions/4236365/python-module-has-no-attribute-mechanize) – Parker Oct 19 '14 at 20:53

2 Answers2

2

Change your filename from mechanize.py. Python is importing your file as the module, instead of importing the mechanize library.

Parker
  • 8,539
  • 10
  • 69
  • 98
1

Rename your filename to something other than mechanize.py

Giving files names same as that of the modules imported causes the file to be imported instead of the intended module.

Alfie
  • 2,706
  • 1
  • 14
  • 28