class Gizmo:
def __init__(self,n):
self._x = n
def __str__(self):
return "I AM A GIZMO # "+str(self._x)
g1 = Gizmo(22)
g2 = Gizmo(44)
print(g1)
I AM A GIZMO # 22
str(g2)
'I AM A GIZMO # 44'
g2
<__main__.Gizmo at 0x10515bac0>
class Gizmos:
def __init__(self):
self._data = []
def addGizmo(self,g):
self._data.append(g)
def __str__(self):
result = ""
for g in self._data:
result = result + str(g) + "\n"
return result
gs = Gizmos()
gs.addGizmo(g1)
gs.addGizmo(g2)
print(gs)
I AM A GIZMO # 22 I AM A GIZMO # 44