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

Gabriel Genellina gagsl-py at yahoo.com.ar
Sat Feb 24 23:54:11 EST 2007


En Sat, 24 Feb 2007 21:29:13 -0300, Charles D Hixson  
<charleshixsn at earthlink.net> escribió:

> Sorry, the "script" hasn't been written.  But Python apparently *won't*
> (automatically) do what I want, which is create a class whose
> sub-classes automatically have unique class variables of a determined
> form such that I can do a hierarchical search through them.  (I could
> plausibly handle this for the instance case but "class variables are
> static", so it looks like I can't do it for class variables in a
> straightforward manner.  This looks like it's going to demand a factory
> method, or some alternate approach.  (Not sure yet which I'll choose.)

"Class variables are static" until you assign to them a new value, then  
become instance (normal) attributes.

class A:
   x = 1

a = A()
a.x # prints 1
a.x = 100
a.x # prints 100
A.x # still 1
b = A()
b.x # still 1

> What I'm looking for is a reasonable way to implement what Marvin Minsky
> calls Panologies.  These are "objects" (my term) with sufficient local
> intelligence to try alternative models of a situation until they find
> one that's appropriate.  E.g., is this being operated on as a physical
> transaction or a social transaction.  (Yes, it is physically happening,
> and it's taking place in physical space, but different models yield
> different analyses of what's happening.  Which is appropriate for the
> situation currently being evaluated?)

You may be interested on Acquisition, a concept from Zope2. Objects not  
only have behavior by nature (inheritance) but nurture (acquisition).  
*Where* an object is contained (or, *how* you reach to it), determines its  
behavior as well as *what* it is.

> P.P.S.:  This isn't all loss.  I'm expecting that eventually I'll start
> running into performance problems, and at that point it would be
> necessary to start translating into a native-compiler language.

Your design seems to be too dynamic to be feasible on a more static  
language.

-- 
Gabriel Genellina




More information about the Python-list mailing list