Ian Bicking: the old part of his blog


I'm in complete agreement with you about a "prohibition"
against attribute access causing side-effects, so long as
we're careful to define side-effects in terms of the
"true job" of the object, not "infrastructure" within the
object (which is to say caching, lazy evaluation, etc.,
would all implicitly induce side-effects in that they would,
respectively, update the cache, set the lazy pointer, etc.)

But to your real point :-) I like to think of the different
accessors as different namespaces. For a long time,
I've wanted to unify those namespaces, but I've finally
realized it's not always possible or desirable to do so.

In fact, in some recent design work I've been doing (no snarky
comments, here, Ian :-) ) on a more intuitive XML <-> Python
object mapping, I've been considering how to deal with the
plethora of namespaces XML has. I'm not even talking about
actual XML Namespaces, but, rather, the different
dimensions along which one can assign names in XML, like
tags/elements, attributes, entities, namespace prefixes, and
so forth.

In figuring out how to "intuitively" map that to Python, I'm
trying to wrap my head around the idea of using __getattr__
and __getitem__ and so forth to break things up and provide
separate namespaces mapping (inasmuch as it's possible) to
the appropriate XML counterparts.

The point of this long-winded comment being that it's quite
possibly instructive to think of .foo and ['foo'] as giving
access to namespaces within the object. Viewed from that
perspective, I'm even all for adding more namespaces and
syntactic sugar to support them :-) (of course, then we
risk wandering into Perl territory).

Imagine a Python that mapped these delimiters to "special"
object methods that you could use to provide various
namespaces of interest in your domain:

foo!bar (not possible?)


I guess there are probably technical reasons to discard a bunch of these (e.g., [[bar]] creates a list within there, and {{bar}} a dict, right?)

But I hope you get my point :-) I mean, aside from destroying Python, which I assure you is not my aim. I'm just thinking aloud here, really.
Comment on So many accessors...
by Tripp Lilley