Skip to content
Discussion options

You must be logged in to vote

I'd do something like this (reduced number of fields for ease of understanding):

message_dict = {}  # Globally available message dict
record = {"src_device": "", "dst_device": "", "time_stamp": ()}  # Record template

def add_record(msg_no, src_device, dst_device, time_stamp):
    record["src_device"] = src_device
    record["dst_device"] = dst_device
    record["time_stamp"] = time_stamp
    message_dict[msg_no] = record.copy()  # Make a copy of the populated template.

This produces the following:

>>> add_record(1, 'test', 'dest', (1,2,3))
>>> add_record(2, 'test_2', 'dest_2', (4,5,6))
>>> message_dict[1]
{'dst_device': 'dest', 'src_device': 'test', 'time_stamp': (1, 2, 3)}
>>> message_dict

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@pollardd
Comment options

@pollardd
Comment options

@Josverl
Comment options

Josverl Dec 30, 2023
Collaborator Sponsor

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@pollardd
Comment options

@pollardd
Comment options

@peterhinch
Comment options

@pollardd
Comment options

Answer selected by pollardd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants