我不知道为什么我一直收到错误 'str' 没有属性 'message'
I don't know why I keep getting the error 'str' has not attribute 'message'
from plyer import notifications
class Reminder():
def __init__(self,message = None):
if not message:
message = input("Please enter the message: ")
self.message = message
print(self.message)
def sendNotification(self):
print(self.message)
notification.notify(title = "Python reminder", message = self.message, app_name = "Python reminder program",app_icon = "",timeout = 10,ticker = "this is ticker thing")
def getTime(self):
pass
Reminder.sendNotification("message")
我得到的错误如下:
回溯(最后一次调用):
文件“c:/Users/yomamahahaha/Desktop/oooohackrrr/actual programs/python/Reminders/reminder.py”,第 28 行,位于
Reminder.sendNotification("可可")
文件“c:/Users/yomamahahaha/Desktop/oooohackrrr/actual programs/python/Reminders/reminder.py”,第 20 行,在 sendNotification 中
打印(self.message)
AttributeError: 'str' 对象没有属性 'message'
您没有创建 Reminder 的实例
所以当你打电话时
Reminder.sendNotification("message")
您在此处将 'self' 设置为“消息”:然后调用 "message".message
,它不存在
def sendNotification(self):
print(self.message)
我想你是说
myReminder = Reminder("Message")
myReminder.sendNotification()
from plyer import notifications
class Reminder():
def __init__(self,message = None):
if not message:
message = input("Please enter the message: ")
self.message = message
print(self.message)
def sendNotification(self):
print(self.message)
notification.notify(title = "Python reminder", message = self.message, app_name = "Python reminder program",app_icon = "",timeout = 10,ticker = "this is ticker thing")
def getTime(self):
pass
Reminder.sendNotification("message")
我得到的错误如下:
回溯(最后一次调用): 文件“c:/Users/yomamahahaha/Desktop/oooohackrrr/actual programs/python/Reminders/reminder.py”,第 28 行,位于 Reminder.sendNotification("可可") 文件“c:/Users/yomamahahaha/Desktop/oooohackrrr/actual programs/python/Reminders/reminder.py”,第 20 行,在 sendNotification 中 打印(self.message) AttributeError: 'str' 对象没有属性 'message'
您没有创建 Reminder 的实例
所以当你打电话时
Reminder.sendNotification("message")
您在此处将 'self' 设置为“消息”:然后调用 "message".message
,它不存在
def sendNotification(self):
print(self.message)
我想你是说
myReminder = Reminder("Message")
myReminder.sendNotification()