Как вызвать функцию без аргументов? - PullRequest
0 голосов
/ 05 февраля 2020

Я пытаюсь вызвать функцию 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 ]

2 голосов
/ 05 февраля 2020

Вы можете использовать аргумент по умолчанию в Python, если вы будете sh вызывать вашу функцию без передачи параметров.

Параметр функции принимает значение по умолчанию, если параметр не предоставляется во время вызова функции.

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)


0 голосов
/ 05 февраля 2020
def functionName(arg = None):
   ''' Your Code '''
   return
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...