Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python getter decorator

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")
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #getter #decorator
ADD COMMENT
Topic
Name
1+5 =