如何在没有参数的情况下调用函数?

时间:2020-02-05 12:28:53

标签: python firebase kivy

我正在尝试调用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)

2 个答案:

答案 0 :(得分:2)

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

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

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)


答案 1 :(得分:0)

def functionName(arg = None):
   ''' Your Code '''
   return