How can I make an existing object read-only?
Duncan Booth
duncan.booth at invalid.invalid
Tue Oct 5 10:40:54 EDT 2004
Alex Martelli wrote:
> Irmen de Jong <irmen at -nospam-remove-this-xs4all.nl> wrote:
>
>> Maybe I'm way off track here, but I want to do something like this:
>>
>> Say I have an object that's initialized with a bunch of attributes.
>> I want to pass the object to a piece of code that is not allowed
>> to add/delete/set attributes on this object.
>> When control returns, the code is again allowed to make changes
>> to the object.
>
> Instead of passing the bare object, pass it wrapped into something like:
>
<snip>
An alternative is just to pass a copy of the object. That way the recipient
can do what they like with it, but the calling code won't see any changes.
More information about the Python-list
mailing list