python - 我不知道为什么我不断收到错误 '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/actualprograms/python/Reminders/reminder.py”,第 28 行,在 Reminder.sendNotification("kek") 文件“c:/用户/yomamahahaha/Desktop/oooohackrrr/actual programs/python/Reminders/reminder.py",第 20 行,在 sendNotification print(self.message) AttributeError: 'str' object has no attribute 'message'
解决方案
您不创建 Reminder 的实例
所以当你打电话时
Reminder.sendNotification("message")
您在此处将“自我”设置为“消息”:然后调用"message".message
,不存在
def sendNotification(self):
print(self.message)
我想你的意思是
myReminder = Reminder("Message")
myReminder.sendNotification()
推荐阅读
- python - 将 txt 文件传递到 pandas 数据帧
- postgresql - 无法从 Tableau srv 连接到 PostgreSQL srv
- php - Symfony 4.4 Auth0 如何从应用程序中完全注销用户
- covariance-matrix - rmvnorm 警告消息:sigma 在数值上不是半正定的
- multithreading - PowerShell 中的 Control.BeginInvoke
- python - 当我使用 beautifulsoup 刮亚马逊时,我没有得到任何输出
- postscript - 写入文件时等价于 ==
- nearprotocol - 在 indexer sync 附近,为什么归档设置为 false 会占用这么多空间?
- python - Python中热图中的索引形状问题
- css - Safari web-inspector(CSS 编辑器)漏洞百出