Maybe something like this:
self.position = [0.0 for _ in self.total_items * self.xyz]
for i in range(self.components):
self.comps[i].position = self.p_offset
self.p_offset += self.comps[i].items
In Python, you can change values inside a class instance variable. This is called "mutating" the instance. If the class doesn't allow this, it is an "immutable" class; if it does allow this, it is a "mutable" class. Strings are immutable, as are integers, but lists are mutable.
In Python, there is no way that I can think of to get a reference to the middle part of a list. Lists are mutable: things can be inserted, deleted, etc. What should the reference do then?
So instead of doing pointer math and storing a reference to a spot within a list, you should just store the offset, and then use the offset to index the list when you need to reference that spot in the list.
For your specific question:
self.comps[N].position = [1,2,3,4]
This would rebind the name position
inside the self.comps[N]
object to now point to a newly created list instance with the value [1, 2, 3, 4]
and would not affect self.position
at all. However, if you just set self.comps[i].position
to index values you could use this code:
i = self.comps[N].position
lst = [1, 2, 3, 4]
self.position[i:i+len(lst)] = lst
This would use a "slice" into the self.position
list to replace the values.
Note that if you use SciPy or even just NumPy, you can define a numpy.array
which is not dynamic; and you can use "views" to get a reference to just part of the list. You might want to look into that, especially if you are working with really large arrays or matrices.
View onto a numpy array?