(Oct-29-2017, 11:53 PM)QueenSvetlana Wrote: Why not use the getters/setter?
Python is not Java(2004)
Quote:Getters and setters are evil. Evil, evil, I say! Python objects are not Java beans.
Do not write getters and setters.
This is what the 'property' built-in is for.
And do not take that to mean that you should write getters and setters, and then wrap them in 'property'.
That means that until you prove that you need anything more than a simple attribute access,don't write getters and setters.
They are a waste of CPU time, but more important, they are a waste of programmer time.
Not just for the people writing the code and tests, but for the people who have to read and understand them as well.
class Student(): def __init__(self, id, first_name, last_name, type_of_student): self.id = id self.first_name = first_name self.last_name = last_name self.type_of_student = type_of_student def international_documents(self, documents): return documents def __str__(self): return f'ID: {self.id} First: {self.first_name} Last Name: {self.last_name} Type: {self.type_of_student}'Use:
>>> Superman = Student(100, 'Clark', 'Kent', 'International') >>> Superman.id 100 >>> Superman.last_name 'Kent' >>> print(Superman) ID: 100 First: Clark Last Name: Kent Type: International >>> Superman.international_documents('born Kal-El on the planet Krypton') 'born Kal-El on the planet Krypton'As you see there is no problem to access data attribute directly,no need for getters/setters.
So can have in information doc that International need to apply doc.
Can also make a check that International most apply doc.