Object's nesting scope
szport at gmail.com
Sun Aug 30 09:15:41 CEST 2009
On 30 авг, 03:22, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Sat, 29 Aug 2009 04:34:48 -0300, zaur <szp... at gmail.com> escribió:
> > On 29 авг, 08:37, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> >> En Fri, 28 Aug 2009 15:25:55 -0300, zaur <szp... at gmail.com> escribió:
> >> > On 28 авг, 16:07, Bruno Desthuilliers <bruno.
> >> > 42.desthuilli... at websiteburo.invalid> wrote:
> >> >> zaur a écrit :
> >> >> > Ok. Here is a use case: object initialization.
> >> >> Err... Looks like you really should read the FineManual(tm) -
> >> >> specifically, the parts on the __init__ method.
> >> > What are you doing if 1) classes Person and Address imported from
> >> > foreign module 2) __init__ method is not defined as you want?
> >> Welcome to dynamic languages! It doesn't matter *where* the class was
> >> defined. You may add new attributes to the instance (even methods to
> >> the class) at any time. [...4 examples...]
> > I know about these ways of object initializing. What I said is about
> > using object's dictionary as nested scope in code block. Object
> > initialization is just one use case.
> > So we say about different things.
> Well, you asked how to proceed in certain cases and I showed several ways
> it can be done right now, without requiring a new scope. You'll have to
> think of another use case.
> Attribute lookup is explicit in Python, and that's a very good thing. If
> you follow the python-ideas thread posted earlier, you'll see the kind of
> problems an implicit attribute lookup would cause. The "with" statement is
> necesary (and a good thing) in Pascal, but not in Python.
> Zope2 departs from this explicitness: it has a <dtml-with> construct
> (similar to what you propose), and I hate it profoundly every time I have
> to edit a DTML file - I can never tell *where* an attribute comes from.
> Another related "feature" is acquisition, a stack of namespaces where
> objects "inherit" attributes from their containers. Same thing, a complete
> waste of time every time I have to track a bug.
> Unless you can find a very compeling use case, I don't think this feature
> will become part of the language anytime soon...
> Gabriel Genellina
The same can be said about multiple inheritance.
However, multiple inheritance is a powerful tool in the hands of
someone who can properly and effectively use it.
More information about the Python-list