I am new in Python and in OOP in general. I have an error "...instance has no attribute '__getitem__'"
, and I understand that the object I have created is not a list. How can I make to be a list object. Here is the class file:
#!/usr/bin/python -tt
import math, sys, matrix, os
class Point:
'Class for points'
pointCount = 0
def __init__(self, x, y, z):
'initialise the Point from three coordinates'
self.x = x
self.y = y
self.z = z
Point.pointCount += 1
def __str__(self):
'print the Point'
return 'Point (%f, %f, %f)' %(self.x, self.y, self.z)
def copyPoint(self, distance):
'create another Point at distance from the self Point'
return Point(self.x + distance[0], self.y + distance[1], self.z + distance[2])
def __del__(self):
'delete the Point'
Point.pointCount -= 1
#print Point.pointCount
return '%s deleted' %self
I need to have it as a point with three coordinates inside (x, y, z), and those coordinates must be "callable" like in a list instance with [].
I have read similar topics but did not understand much. Please describe it in simple words and with examples.