I have the following problem, i am an amateur user of Python scripting. I have created the following class
roof_height = 3.5 #m
E = 30000*(10^3) #kN/m^2
class Brace():
_registry = []
def __init__(self,name,coord,b,d, h = roof_height):
print('Brace created.')
Brace._registry.append(self)
self.name = name
self.coord = coord # pass tuple in the form of (x,y)
self.b = b # //x global
self.d = d # //y global
self.h = h
def __del__(self):
print('Destructor called, Brace deleted.')
Brace._registry.remove(self)
def properties(self):
print("properties of " + self.name + " calculated")
As = self.b*self.d
Iy = self.b*(self.d**3)*(1/12)
Iz = (self.b**3)*(self.d)*(1/12)
self.Iy = Iy
self.Iz = Iz
self.As = As
def stiffness(self):
print("stiffnesses of " + self.name + " calculated")
Kx = 12*E*self.Iy/self.h
Ky = 12*E*self.Iz/self.h
self.Kx = Kx
self.Ky = Ky
I have created the _registry general property of the class so I can iterate through the objects, which works fine. The problems that I am facing are the following: 1. When I am creating an object the print out
'Brace created'
is displayed, but when I am deleting it the message
'Destructor called, Brace deleted.'
is not displayed while the object is deleted, also the _registry list remains the same without deleting the object. The length of the list obviously remains the same.
- How can I avoid creating the same instance twice with the same name, I mean how can I check for duplicate instances (same object name and attribute values) Do I have to write a code for it or is there a builtin function that I can use?