gpt4 book ai didi

Python: AttributeError: 'builtin_function_or_method' 对象没有属性 'sleep'

转载 作者:太空宇宙 更新时间:2023-11-04 07:05:23 24 4
gpt4 key购买 nike

我在运行我的程序时收到一个奇怪的错误?我不确定为什么它不让我休眠。

Traceback (most recent call last):
Not an add minute at all.
File "C:/Users/admin/PycharmProjects/test/odd.py", line 15, in <module>
time.sleep(0.05)
AttributeError: 'builtin_function_or_method' object has no attribute 'sleep'

代码:

from datetime import datetime
from time import time
from random import random

odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]

right_this_minute = datetime.today().minute

for i in range(0, 11):
if right_this_minute in odds:
print("This minute seems a little odd.")
else:
print("Not an add minute at all.")

time.sleep(random.randint(1, 60))

最佳答案

from time import time更改为from time import sleep

那你可以直接使用sleep代替time.sleep

关于Python: AttributeError: 'builtin_function_or_method' 对象没有属性 'sleep',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51466064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com