I am trying to import the time
module to be able to use the time.sleep(secs)
functionality.
我正在尝试导入时间模块,以便能够使用time.sleep(secs)功能。
The problem I think which might be there is the fact that I have also imported datetime
and that might be messing it up
我认为可能存在的问题是我还导入了日期时间,这可能会搞砸它
import datetime
import time
.
.
some code utilizing `datetime`
.
.
time.sleep(seconds)
The error I am getting is : AttributeError: 'function' object has no attribute 'time'
我得到的错误是:AttributeError:'function'对象没有属性'time'
2 个解决方案
#1
14
You've almost certainly defined a variable or a function called time
. Try renaming it.
你几乎肯定定义了一个变量或一个叫做time的函数。尝试重命名它。
#2
2
Possibly you have set
可能你已经设置好了
time = 3
时间= 3
Or some other number of seconds to sleep, earlier, overshadowing the time module. But this would usually give an AttributeError: 'int' object has no attribute 'sleep'
, so I'm not 100% sure. There should be no problem to import datetime and then import time.
或者早些时候睡觉的其他几秒钟,使时间模块黯然失色。但这通常会产生一个AttributeError:'int'对象没有属性'sleep',所以我不是100%肯定。导入日期时间然后导入时间应该没有问题。
You must have assigned something else to time, which you have not provided in your code, else you would be getting TypeError: a float is required
when calling time.sleep(time)
. So can you post more of your code?
您必须已经为时间分配了其他内容,而这些内容尚未在代码中提供,否则您将获得TypeError:调用time.sleep(time)时需要float。那么你可以发布更多的代码吗?
#1
14
You've almost certainly defined a variable or a function called time
. Try renaming it.
你几乎肯定定义了一个变量或一个叫做time的函数。尝试重命名它。
#2
2
Possibly you have set
可能你已经设置好了
time = 3
时间= 3
Or some other number of seconds to sleep, earlier, overshadowing the time module. But this would usually give an AttributeError: 'int' object has no attribute 'sleep'
, so I'm not 100% sure. There should be no problem to import datetime and then import time.
或者早些时候睡觉的其他几秒钟,使时间模块黯然失色。但这通常会产生一个AttributeError:'int'对象没有属性'sleep',所以我不是100%肯定。导入日期时间然后导入时间应该没有问题。
You must have assigned something else to time, which you have not provided in your code, else you would be getting TypeError: a float is required
when calling time.sleep(time)
. So can you post more of your code?
您必须已经为时间分配了其他内容,而这些内容尚未在代码中提供,否则您将获得TypeError:调用time.sleep(time)时需要float。那么你可以发布更多的代码吗?