serhii.net

In the middle of the desert you can say anything you want

14 Sep 2022

Python @property decorator

Python has a property function/decorator: Built-in Functions — Python 3.10.7 documentation.

Basically - you have a field and you want getter/setter functions on it.

Seen first in konfuzio_sdk, sample from there:

@property
def number_of_lines(self) -> int:
	"""Calculate the number of lines in Page."""
	return len(self.text.split('\n'))

Then you can run document.number_of_lines and it runs the function.

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus