【发布时间】:2014-05-28 13:23:43
【问题描述】:
我正在制作一个闹钟程序,它必须在早上 6:00 之前睡觉(不发出声音)。我遇到的问题是我无法让程序等待 X 秒
伪代码: X = 上午 6:00 - 当前时间 time.sleep(X)
到目前为止,这是我的代码:
#Imports
import datetime
import time
import pygame
WORDS = ["Wake", "Me", "Tommorow"]
#Make J.A.R.V.I.S. Listen
mic.activeListen():
#Determine time and difference of time
x = datetime.datetime.now()
x = x.total_seconds
print(x)
x = datetime.timedelta()
x = float(x) #time.sleep() Requires a float value.
time.sleep(x) #Sleeps until 6:00 AM
pygame.mixer.init()
pygame.mixer.music.load("alarm.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
【问题讨论】:
-
早上 6:00 的定义在哪里?
-
print(x)得到什么? -
在
sleep使用之前尝试打印x -
另外,
total_seconds()是在timedelta上定义的,而不是datetime
标签: python datetime time pygame timedelta