(Dec-24-2020, 08:13 PM)bowlofred Wrote: You call it a copy, but there are no copies made anywhere. When you pass an object to a function, if that object is mutable the function can modify it.
Here you pass dict1 to upd_dict1 on line 19. This function both modifies the object that is passed in, and returns another reference to that object.
Before line 19 you have two dictionaries: dict_1 and dict_2. After line 19, both variables point at the same object (the original dict_2 is discarded). Line 24 doesn't do anything because they are already the same. You can add a statement like:
print(f"dict_1 and dict_2 are the same object: {dict_1 is dict_2}"
Thank you. The thing I am trying to fix is that when I do this in a third-level function:
for curr_id in dict_1: # loop through the dictionary # code code code dict_1[curr_id].incl_ips.append(ipaddress.ip_network(rng_chop[0] + "/" + str(myprefix), False)) # code code codeit appends the value in the loop iteration to THE SAME dictionary entry.
Also, from my OP, essentially dict_1_copy is discarded when I exit the function and recreated the next time the function is called?