It's widely agreed that Python's properties are not merely a kludge for working around the past mistake of exposing of publicly exposing data members. But then when is it not Pythonic to use a property instead of a method that doesn't take any arguments?
For example, if we were writing the Python standard library from scratch, would it be more Pythonic to replace dict.items()
with dict.items
? We could even add a setter with perfectly intuitive behavior. That feels wrong but I can't articulate rules for what is and isn't a Pythonic use of properties that would disqualify this use. One obvious rule might be that if there's no reasonable setter, then properties shouldn't be used. That disqualifies dict.values()
and dict.keys()
but not dict.items()
.
Obviously style can be subjective, but since it's a Python motto that "There should be one -- and preferably only one -- obvious way to do it.", I think this question is reasonable. Also, let's try to stick to the PEPs and code in the Python standard library.