Dec-07-2017, 04:48 PM
(Dec-07-2017, 04:31 PM)QueenSvetlana Wrote:(Dec-07-2017, 04:26 PM)Windspar Wrote: @Mekire @snippsat
It might not be absolute private and name mangling. But docs say to use as such. section 9.6
So it is python way of support private class variables.
That being said, what is the Python way to create a variable and only allow a getter? Or tell the person using my code, this variable after object construction should be read-only.
Essentially you create a "getter" without the @property keyword. Suppose I want to keep it pure Python, so my class looks like this:
class Car: def __init__(self, ID, name, tire, engine): self.ID = ID self.name = name self.tire = tire self.engine = engineHow would I let client code know to use them as read only, if "getters" are not the Python way?