Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在没有参数的情况下调用函数?_Python_Firebase_Kivy - Fatal编程技术网

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

Python 如何在没有参数的情况下调用函数?,python,firebase,kivy,Python,Firebase,Kivy,我正在尝试调用def listener函数,但我对firebase streaming不太熟悉,因此我不知道event参数是如何工作的,没有该参数我无法调用该函数。任何知道我的人都可以调用这个方法。我将不胜感激 class Notifications(Screen): notificationslist = ObjectProperty(None) def listener(self, event): notifications_screen = self.mana

我正在尝试调用
def listener
函数,但我对firebase streaming不太熟悉,因此我不知道
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)

如果希望在不传递参数的情况下调用函数,可以在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)


如果希望在不传递参数的情况下调用函数,可以在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)




如果不传递任何参数,您希望函数做什么?这看起来像是不显式调用
listener
;您可以将其作为回调函数提供给其他对象,以便使用适当的参数进行调用。所有函数中都使用参数
event
。在这种情况下,您似乎不能“忘记”这个参数,因为所有函数都在
事件
@RomainF的属性上工作。您知道我可以用什么其他方法调用它吗?如果您想调用这个函数,您需要一个
事件
,具有正确属性,包括
事件类型
路径
数据
。。。问题是为什么需要调用此函数?我同意@chepner的观点,
listener
不应由用户调用,而是由其他函数在内部使用。如果不传递任何参数,您希望函数做什么?这看起来像是不显式调用
listener
的情况;您可以将其作为回调函数提供给其他对象,以便使用适当的参数进行调用。所有函数中都使用参数
event
。在这种情况下,您似乎不能“忘记”这个参数,因为所有函数都在
事件
@RomainF的属性上工作。您知道我可以用什么其他方法调用它吗?如果您想调用这个函数,您需要一个
事件
,具有正确属性,包括
事件类型
路径
数据
。。。问题是为什么需要调用此函数?我同意@chepner的观点,即用户不应该调用
listener
,而是由其他函数在内部使用。如果您解释为什么这是首选解决方案,并解释它是如何工作的,那么这将更有帮助。我们想要教育,而不仅仅是提供代码。@theTinMan我试图永远运行代码,但我不知道怎么做that@theTinMan要运行它,只有当流中有新数据时,通知列表才会更新。请提供任何帮助。发帖的人需要解释代码,为什么它有用,同时可以解释如何让它做你想做的事情。这就是我们应该如何回答这样的问题。如果这个问题没有帮助,那么请随意否决它。如果你解释为什么这是首选解决方案,并解释它是如何工作的,这会更有帮助。我们想要教育,而不仅仅是提供代码。@theTinMan我试图永远运行代码,但我不知道怎么做that@theTinMan要运行它,只有当流中有新数据时,通知列表才会更新。请提供任何帮助。发帖的人需要解释代码,为什么它有用,同时可以解释如何让它做你想做的事情。这就是我们应该如何回答这样的问题。如果这个问题没有帮助,那么请随意否决它。