[Python-Dev] PEP 3101 Update

Steven Bethard steven.bethard at gmail.com
Mon May 8 03:37:10 CEST 2006


On 5/6/06, Talin <talin at acm.org> wrote:
> I've updated PEP 3101 based on the feedback collected so far.
[snip]
>      Compound names are a sequence of simple names seperated by
>      periods:
>
>          "My name is {0.name} :-\{\}".format(dict(name='Fred'))
>
>      Compound names can be used to access specific dictionary entries,
>      array elements, or object attributes.  In the above example, the
>      '{0.name}' field refers to the dictionary entry 'name' within
>      positional argument 0.

I'm still not a big fan of mixing together getitem-style access and
getattribute-style access.  That makes classes that support both
ambiguous in this context.  You either need to specify the order in
which these are checked (e.g. attribute then item or item then
attribute), or, preferably, you need to extend the syntax to allow
getitem-style access too.

Just to be clear, I'm not suggesting that you support anything more
then items and attributes.  So this is *not* a request to allow
arbitrary expressions.  In fact, the only use-case I see in the PEP
needs only item access, not attribute access, so maybe you could drop
attribute access?

Can't you just extend the syntax for *only* item access?  E.g. something like:

    "My name is {0[name]} :-\{\}".format(dict(name='Fred'))


STeVe
--
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy


More information about the Python-Dev mailing list