I have a Note Class as follows with two properties:
class Note(dict):
def init(self, name: str, vex: str):
dict.init(self, name=name, vex=vex)
self.name = name
self.vex = vex
(The dict is there to allow json to serialize it using json.dumps.)
I have a List of note which first populates only the name and then a function populates the vex property.
When the function returns, all of the vex properties are empty.
Just before the return I have added the following debug code:
for i in range(len(notes)):
print(notes[i].vex)
print(notes)
This outputs:
C/5
D/5
E/5
F/5
G/5
A/5
B/5
C/6
[{‘name’: ‘C’, ‘vex’: ”}, {‘name’: ‘D’, ‘vex’: ”}, {‘name’: ‘E’, ‘vex’: ”}, {‘name’: ‘F’, ‘vex’: ”}, {‘name’: ‘G’, ‘vex’: ”}, {‘name’: ‘A’, ‘vex’: ”}, {‘name’: ‘B’, ‘vex’: ”}, {‘name’: ‘C’, ‘vex’: ”}]
So, as you can see, the vex values are there when accessed individually in the loop, but not there when the whole list is printed.
The function is then serialized to json and passed onto another system – the vex values are similarly missing from the json.
Daniel Davis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.