首页 > 解决方案 > 如何调用没有参数的函数?

问题描述

我正在尝试调用该 def listener函数,但我是 firebase 流的新手,所以我不知道 event参数是如何工作的,而且我无法在没有参数的情况下调用该函数。无论如何,任何知道我都可以调用该方法的人。我会很感激。


class Notifications(Screen):
    notificationslist = ObjectProperty(None)

 def listener(self, event):
        notifications_screen = self.manager.get_screen('notif')
        print(event.event_type)  # can be 'put' or 'patch'
        print(event.path)  # relative to the reference, it seems
        print(event.data)  # new data at /reference/event.path. None if deleted
        notifications = event.data
        if notifications.items() == None:
            return
        else:
            for key, value in notifications.items():
                thevalue = value
                notifications_screen.notificationslist.adapter.data.extend([value[0:17] + '\n' + value[18:]])
                print(thevalue)
                id = (thevalue[thevalue.index("(") + 1:thevalue.rindex(")")])
                print(id)

标签: pythonfirebasekivy

解决方案


如果您希望在不传递参数的情况下调用函数,则可以在 Python中使用默认参数。

如果在函数调用期间未提供参数,则函数参数采用默认值。

class Notifications(Screen):
    notificationslist = ObjectProperty(None)

 def listener(self, event = None):
        notifications_screen = self.manager.get_screen('notif')
        print(event.event_type)  # can be 'put' or 'patch'
        print(event.path)  # relative to the reference, it seems
        print(event.data)  # new data at /reference/event.path. None if deleted
        notifications = event.data
        if notifications.items() == None:
            return
        else:
            for key, value in notifications.items():
                thevalue = value
                notifications_screen.notificationslist.adapter.data.extend([value[0:17] + '\n' + value[18:]])
                print(thevalue)
                id = (thevalue[thevalue.index("(") + 1:thevalue.rindex(")")])
                print(id)



推荐阅读