rossengeorgiev / aprs-python

📡 Python module for working with APRS
http://aprs-python.readthedocs.io/en/latest/
GNU General Public License v2.0
118 stars 37 forks source link

Understanding callback function #47

Closed ivanmartinezmorales closed 6 years ago

ivanmartinezmorales commented 6 years ago

As I understand, when a line is received, it is passed to the callback function

        if not self._connected:
            raise ConnectionError("not connected to a server")

        line = b''

        while True:
            try:
                for line in self._socket_readlines(blocking):
                    if line[0:1] != b'#':
                        if raw:
                            callback(line)
                        else:
                            callback(self._parse(line))

How do I send the dictionary produced by:

callback(self._parse(line))

from

def callback(packet):
    print(packet)

outside of the local scope of the callback function? Every time I have tried, I come up with empty sets. I don't know what I am doing wrong. Here is a snippet of the code I used:

packet_list = []
def callback(packet):
    packet = list(packet) # I would like the whole packet, outside of this function
    packet_list.append(packet)
    return packet_list

but when I print the n-th term of the packet, I get nothing.

ivanmartinezmorales commented 6 years ago

Solved my own issue. Thank you everyone.