How to build Hierarchies of dict's? (Prototypes in Python?)

Charles D Hixson charleshixsn at earthlink.net
Fri Feb 23 19:46:44 EST 2007


Larry Bates wrote:
> Charles D Hixson wrote:
>   
>> I'm sure I've read before about how to construct prototypes in Python,
>> but I haven't been able to track it down (or figure it out).
>>
>> What I basically want is a kind of class that has both class and
>> instance level dict variables, such that descendant classes
>> automatically create their own class and instance level dict variables. 
>> The idea is that if a member of this hierarchy looks up something in
>> it's local dict, and doesn't find it, it then looks in the class dict,
>> and if not there it looks in its ancestral dict's.  This is rather like
>> what Python does at compile time, but I want to do it at run time.
>>
>> I'm sure I've seen how to do it...but have no idea where, or what it was
>> called, or when (probably around the time Prothon was being discussed,
>> as I have the idea of prototype associated with it for no clear reason).
>>     
>
> What you describe is exactly how Zope works so you might want to spend
> some time looking at it.
>
> http://www.zope.org
>
> -Larry
>   
Thanks for the suggestion, and I'll do that if I must, but Zope is 
pretty heavy to drag into something for just one function, and I don't 
really see any use for most parts of it in what I'm doing.  And that's a 
LOT of code to wade through for one technique.




More information about the Python-list mailing list