📜  python getter 装饰器 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:29.739000             🧑  作者: Mango

代码示例1
class Person(object):
    def __init__(self, p_name=None):
        self.name = p_name

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, new_name):
        if type(new_name) == str: #type checking for name property
            self._name = new_name
        else:
            raise Exception("Invalid value for name")