Property Descriptor - Public Getter, Private Setter

Diez B. Roggisch deets at nospam.web.de
Wed Jul 18 11:37:50 EDT 2007


gamehack wrote:

> Hi all,
> 
> I was looking around the net to figure out how I can use the
> property() descriptor to make a property readable by everyone and only
> settable by the class or any derived classes. Thanks.

Forget it. You can try and come up with an implementation that will check
the stack-frames and try and see if the callers belong to the current
class, or some subclass.

But then if somebody wants to accomplish the setting by all means, he/she
just adds a new setter method to your class, and that's it.

What's your usecase? If you give us that, there might be better suggestions.

Diez



More information about the Python-list mailing list