【发布时间】:2020-12-15 00:18:09
【问题描述】:
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")
我得到的错误如下:
Traceback(最近一次调用最后一次): 文件“c:/Users/yomamahahaha/Desktop/oooohackrrr/actual programs/python/Reminders/reminder.py”,第 28 行,在 Reminder.sendNotification("kek") 文件“c:/Users/yomamahahaha/Desktop/oooohackrrr/actual programs/python/Reminders/reminder.py”,第 20 行,在 sendNotification 打印(self.message) AttributeError: 'str' 对象没有属性 'message'
【问题讨论】:
-
如何共享实际上给您错误的代码部分?您给我们的内容中没有第 28 行。您也没有初始化该类的实例(假设
Reminder不是变量,而是试图实例化该类)。您还将消息传递给不带参数的sendNotification方法。应该是这样的:Reminder('message').sendNotification().
标签: python class attributeerror self