Newbie: question regarding references and class relationships

Rui Maciel rui.maciel at gmail.com
Mon Jun 10 09:57:43 EDT 2013


Roy Smith wrote:

> Have you tried running the code you wrote?  It does that already!  When
> you do something like:
> 
> my_list = [obj1, obj2]
> 
> in Python, the objects are stored by reference (not just lists, all
> assignments are by reference).

I've tested the following:

<code>
model = Model()
model.points.append(Point(1,2))
model.points.append(Point(1,4))

line = Line( model.points[0], model.points[1])

# Case A: this works
model.points[0].position = [2,3,4]
line.points

# Case B: this doesn't work
test.model.points[0] = test.Point(5,4,7)
line.points
</code>


Is there a Python way of getting the same effect with Case B?


Thanks in advance,
Rui Maciel



More information about the Python-list mailing list