Reputation: 9
I've written this code for an the alarm clock portion of a project I am working on (coffee brewing alarm clock). When I run the program it either just skips to the "yikes..." portion or returns the error
AttributeError: 'str' object has no attribute 'start'
Does anyone have any ideas on how to get this fixed and the alarm clock working? I just need a fresh set of eyes as I am still new to python and have been looking at the code for too long now.
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()
Upvotes: 0
Views: 891
Reputation: 11
I'm not entirely sure what you're trying to do with that end loop, but i believe that the reason it is giving you that error is because you're trying to reference user_input as if it is a function. Maybe you were trying to just wait for the user to enter something? if so...
Try changing this:
text = str(user_input())
to this:
text = str(input(''))
Upvotes: 1