Help us understand the problem. What is going on with this article?

setter, getter

More than 5 years have passed since last update.

デコレータを利用しない

class Poko:
    def __init__(self):
        self._hoge = "hoge"

    def get_hoge(self):
        return self._hoge

    def set_hoge(self, value):
        self._hoge = value

    def del_hoge(self):
        del self._hoge

    hoge = property(get_hoge, set_hoge, del_hoge)

する

class Poko:
    def __init__(self):
        self._hoge = "hoge"

    @property
    def hoge(self):
        return self._hoge

    @hoge.setter
    def hoge(self, value):
        self._hoge = value

    @hoge.deleter
    def hoge(self):
        del self._hoge

実行は

poko = Poko()
poko.hoge = "pokopoko"
print poko.hoge
del poko.hoge

みたいに

fukkyy
Gunosyの中の人
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away