I am learning python by implementing a website with fastApi ; I have many years of experience in C#. I have this code :
testModule.py :
class testClass:
async def test(self):
r = DataSet()
for i in range(0, 10):
r.Tables.append(Table())
r.Tables[i].Rows.append(dict[int, int]())
r.Tables[i].Rows[0][0] = 0
Dataset.py:
class Table:
Rows: list[dict[str, Any]] = []
class DataSet:
Tables: list[Table] = []
testModule.py :
class testClass:
async def test(self):
r = DataSet()
for i in range(0, 10):
r.Tables.append(Table())
r.Tables[i].Rows.append(dict[int, int]())
r.Tables[i].Rows[0][0] = 0
main.py :
@app.get("/test")
async def test(instance: Annotated[testClass, Depends()]):
res = await instance.test()
return res
When I call the test route and I set a breakpoint on the line r.Tables[i].Rows[0][0] = 0
, at the second loop, my debugger shows me this :
Why the second Table instance already contains items, even if I didn’t add any yet ?