AttributeError: 'module' object has no attribute 'webdriver' - python

AttributeError: 'module' object has no attribute 'webdriver'
why this error happen when write
import selenium
and when write code like this no error happen
from selenium import webdriver

You get an error because webdriver is a module inside the selenium module, and you can't access modules without an explicit import statement.
If you take a look at help(selenium), you'll see there are two modules and one non-module contained inside.
PACKAGE CONTENTS
common (package)
selenium
webdriver (package)
And it behaves according to what I described above:
>>> selenium.common # doesn't work
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'common'
>>> from selenium import common # works
>>> selenium.selenium # works
<class 'selenium.selenium.selenium'>
>>> selenium.webdriver # doesn't work
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'webdriver'
>>> from selenium import webdriver # works
>>>

Related

How to read Python json file?AttributeError: '_io.TextIOWrapper' object has no attribute 'load'

I am trying to load my json file. I am new to MacOS,but that should be the problem. My code
from terminal
import json
>>> with open('ticr_calculated_3_2020-05-27T11-01-30.json','r+', encoding='utf-8') as f:
data=json.load(f)
I got error
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: '_io.TextIOWrapper' object has no attribute 'load'
The same error happens with json example from Python docs
json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: '_io.TextIOWrapper' object has no attribute 'dumps'
Why?
Have you written everything into one Python interpreter session? It seems to me that you defined the name json before.
Try opening a new Python interpreter or writing your script into a file.

When I import fileinput module, use the input method , it report AttributeError: 'module' object has no attribute 'input'

The version of python is 2.7.13.
The content of 3.txt is:
this is a river
that is a cloud
the world is beatiful
I write a python script:
import fileinput
def process(string):
print 'Processing: ', string
for line in fileinput.input(r'E:\Python\3.txt'):
process(line)
When I run this script , it report error:
====================== RESTART: E:\Python\fileinput.py ======================
Traceback (most recent call last):
File "E:\Python\fileinput.py", line 1, in <module>
import fileinput
File "E:\Python\fileinput.py", line 7, in <module>
for line in fileinput.input(r'E:\Python\3.txt'):
AttributeError: 'module' object has no attribute 'input'
--------------------------------------------------------------------------------
What is the reason cause this problem ?
How can I slove this problem ?
Don’t name your script “fileinput.py”. It conflicts with the library module of the same name.

'builtin_function_or_method' object has no attribute 'clock'

My following code doesn't work and I don't get why
from time import time
t=time.clock()
print(t)
The error is 'builtin_function_or_method' object has no attribute 'clock'
I don't understand where is the mistake because on all examples I have seen such code should work.
What's more, if I replace time.clock() by time(), the code works (so the library is "recognized").
time has an attribute clock, you are trying to access time.time.clock which does not exist.
>>> import time
>>> time.clock()
0.126727
>>> time.time()
1513247982.472323
>>> time.time.clock
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute 'clock'

AttributeError: 'module' object has no attribute 'TextCalendar'

When I copy the below code in Ideone then it runs fine but it is not running in the text editor and showing the error mentioned in the subject of this post:
import calendar
c = calendar.TextCalendar(calendar.SUNDAY)
c.prmonth(2007, 7)
The complete error is:
Traceback (most recent call last):
File "calendar.py", line 1, in <module>
import calendar
File "/home/shl/Desktop/calendar.py", line 2, in <module>
c = calendar.TextCalendar(calendar.SUNDAY)
AttributeError: 'module' object has no attribute 'TextCalendar'
change the program name from calendar.py to something like calendar_code.py
This wold work properly.
Importing from builtin library when module with same name exists

Printing docstrings in Python 3

How do you print doc strings in python 3.1.x?
I tried with the re and sys modules as a test and I keep getting errors. Thanks
import re
print(re._doc_)
Traceback (most recent call last):
File "<pyshell#91>", line 1, in <module>
print(re._doc_)
AttributeError: 'module' object has no attribute '_doc_'
It's called __doc__, not _doc_.
import re
print(re.__doc__)
Works just fine.

Categories

Resources