'builtin_function_or_method' object has no attribute 'clock' - python

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'

Related

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

im trying to disable auto update in Circutpython 8.0 beta on the pico W and every time I run
import supervisor supervisor.disable_autoreload()
I always get this error
>>> supervisor.disable_autoreload() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'disable_autoreload'
how can I fix this
I had the same issue and I'm not sure why because this function is still in the official documentation. Anyways, this worked for me on en_US-8.0.0-rc.2.
supervisor.runtime.autoreload = False

print (datetime.datetime.now()-datetime.timedelta(days=7)).date() returning NoneType' object has no attribute 'date'

I'm using
print (datetime.datetime.now()-datetime.timedelta(days=7)).date()
in Python 3.6.4 which is returning below error.
The same command is working is python 2.
>>> print (datetime.datetime.now()-datetime.timedelta(days=7)).date()
2020-11-06 16:24:24.728051
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'date'
How to fix this issue?
Have you tried doing this:
from datetime import datetime, timedelta
d = datetime.today() - timedelta(days=days_to_subtract)

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.

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

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
>>>

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

Categories

Resources