[PYTHON] setter, getter

Don't use decorators

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)

To do

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

Execution

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

like

Recommended Posts

setter, getter
setter and getter
Automatically create Java getter / setter definitions