Skip to main content
2 of 3
Improve code formatting, shorten sentences, modify title to make it easier to understand at first glance

Python property with public getter and private setter

I have a python property like this:

class Foo: @property def maxInputs(self): return self._persistentMaxInputs.value @maxInputs.setter def maxInputs(self, value): self._persistentMaxInputs.value = value 

Currently, the value of maxInputs can be get and set by everyone.

However, I want to allow everyone to get the value of the maxInputs, but it should only be set inside of the Foo class.

So is there a way to declare a property with a private setter and a public getter?

MorgoZ
  • 2.1k
  • 5
  • 29
  • 55