Possible to create a read-only complex object?
Chris Rebert
clp2 at rebertia.com
Sun Jul 11 17:22:11 EDT 2010
On Sun, Jul 11, 2010 at 9:51 AM, <python at bdurham.com> wrote:
> 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?
Have you considered just making a deep copy of your object instead?
That way, others could inspect the copy and mess with it all they
want, without affecting the original.
http://docs.python.org/library/copy.html#copy.deepcopy
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list