[Zope-Coders] Re: [ZC] 490/ 2 Resolve ""Object" class for PythonScripts"
Evan Simpson
evan@4-am.com
Thu, 05 Sep 2002 08:59:04 -0500
Casey Duncan wrote:
> Why a __setitem__ as opposed to __setattr__? Is it because that is forbidden
> in general in the bytecode interpreter?
It's not opposed to __setattr__, it's in addition. '_guarded_writes'
allows attributes and items to be set, and the base 'record' class
already provides __getitem__, so a __setitem__ was all it needed.
> I'm a little confused what this gains us over just using a dict (but I am
> happy to be enlightened). Also this should be documented somewhere, like the
> scripting section of the Zope book ;^)
It's useful for constructing data structures for code that expects an
object, not a dict. It's the difference between <dtml-in foo> and
<dtml-in foo mapping>, for example. An Object makes a fine stand-in
where a :record or :records marshalled field was expected.
I'll definitely send Chris a snippet for the Book.
Cheers,
Evan @ 4-am