0

I am writing a python class. I want to write the constructor of the class in a way that allows the students_list to be set if it hasn’t been set already by another instance of the class. So, students_list should be the same list for all the instances of the class. The default value of the students_list is an empty list.

class contactTracker:
 def __init__(self, students_list = [], cases_with_contacts):
    self.students_list = students_list
    self.cases_with_contacts = cases_with_contacts


ct1 = contactTracker([s1,s2,s3],cases_with_contacts)
ct2 = contactTracker(cases_with_contacts)

I have no idea how to do this. Any help would be appreciated.

Note: this cannot be done by static variables as I do not want to define it in a class declaration, I want to define it once in my first instance of the class.

nfn
  • 583
  • 2
  • 7
  • 22

0 Answers0