class Person(object): def __init__(self, name, lastName): self.__name = name self.__lastName = lastName # dynamic attributes @property def name(self): return self.__name @property def lastName(self): return self.__lastName
@name.setter def name(self, value): self.__name = value return self.__name @lastName.setter def lastName(self, value): self.__lastName = value return self.__lastName # read only @property def specie(self): return "Human" # method def fullName(self): return self.name + " " + self.lastName person = Person("Homer", "Simpson") person.name # Result: Homer # person.lastName # Result: Simpson # person.fullName() # Result: Homer Simpson # person.name = "Bart" person.fullName() # Result: Bart Simpson # <-- dinamically computed because name and lastName are properties person.specie # Result: Human # person.specie = "Alien" # AttributeError: can't set attribute # <-- which is fine, because it is read only -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/458042a4-0e7d-4031-b55b-1f4d213dcb20o%40googlegroups.com.