Possible to create a read-only complex object?

python at bdurham.com python at bdurham.com
Sun Jul 11 12:51:28 EDT 2010


I have a complex object with attributes that contain lists, sets,
dictionaries, and other objects. The lists and dictionaries may
themselves contain complex objects.

I would like to provide a read-only version of this type of
object for other developers to query for reporting.

Is there a way to prevent other developers from changing the
attributes of my complex and nested object?

In researching this question, I have identified __setattr__ and
__delattr__ as possible ways to prevent changes to simple
attributes, but I don't believe these magic methods will prevent
others from fiddling with attributes containing lists and
dictionaries or the contents of these lists and dictionaries.

Another idea I had was to create a wrapper object to proxy all
access to the original object. Is there a generic reciepe for
this type of wrapper?

Thank you,
Malcolm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100711/02a6690a/attachment.html>


More information about the Python-list mailing list