【发布时间】:2017-05-23 03:07:56
【问题描述】:
我已经为我正在处理的项目(咖啡冲泡闹钟)的闹钟部分编写了此代码。当我运行程序时,它要么只是跳到“yikes ...”部分,要么返回错误
AttributeError: 'str' 对象没有属性 'start'
有没有人知道如何解决这个问题并让闹钟正常工作?我只需要一双新的眼睛,因为我还是 python 新手,而且已经看代码太久了。
import time
import os
import threading
class Alarm(threading.Thread):
def __init__(self, hours, minutes):
super(Alarm, self).__init__()
self.hours = int(hours)
self.minutes = int(minutes)
self.keep_running = True
def run(self):
try:
while self.keep_running:
now = time.localtime()
if (now.tm_hour == self.hours and now.tm_min == self.minutes):
print("ALARM NOW!")
os.popen("bensound-dubstep.mp3")
return
time.sleep(60)
except:
return
def just_die(self):
self.keep_running = False
print("Enter your name: ")
user_input=input(":")
print("Hello, " + user_input)
alarm_HH = input("Enter the hour you want to wake up at: ")
alarm_MM = input("Enter the minute you want to wake up at: ")
print(("You want to wake up at: " + alarm_HH + ':' + alarm_MM).format(alarm_HH, alarm_MM))
alarm=("class Alarm")
class Alarm (Alarm(alarm_HH, alarm_MM)):
alarm.start()
try:
while True:
text = str(user_input())
if text == "stop":
alarm.just_die()
break
except:
print("Yikes lets get out of here")
alarm.just_die()
【问题讨论】:
-
欢迎来到 Stackoverflow。您的问题标题并没有过多地揭示您遇到的问题。你能改进它吗?还要考虑How do I ask a good question 并提供Minimal Complete Verifiable Example 您的问题。
标签: python raspberry-pi clock alarm