I have a class file:
class Land:
id = None
blocks = []
class Block:
blockId = None
blockName = None
I am going through a long list of json data and creating land with blocks inside it. The code is similar to:
for value in jsonList:
l = Land()
l.id = value.id
for block in value.blocks:
b = Block()
blockId = block.id
blockName = block.name
l.blocks.append(b)
when I later look at this, every land item in the array, has EVERY block added, so it doesn't seem to be creating new instances of the Land.blocks list when I create a new land object, it's referencing the previous one.
What am I doing wrong here? (I'm used to the new keyword in C# and clearly missing reference or something?)
Edit:
I think based on the comments below I need to do?:
class Land:
def __init__(self):
self.id = None
self.Blocks = []
class Block:
def __init__(self):
self.blockId = None
self.blockName = None