Python language suggestion

Andrew Dalke dalke at acm.org
Fri Jan 12 00:13:22 EST 2001


Erik Max Francis wrote in message <3A5E1D2B.1DC60661 at alcyone.com>...
>Chris Ryland wrote:
  ...
>> I realize that foo['bar bletch'] is just as good for dictionary-like
>> objects, but foo.'bar bletch' would be very much more attractive in
>> one
>> application I'm considering (
 ...
>This does not sound like a good idea.  Indexes of an object which
>supports __getitem__ are totally independent of the attributes which
>that object may have; comingling them with a similar syntax doesn't seem
>like it would gain anything except confusion.
>
>I mean, really -- is it that much easier to write object.key instead of
>object[key]?

I believe he means
  foo.'bar bletch'
as an alternate way of doing
  getattr(foo, 'bar bletch')

not as foo['bar bletch']

I'm mulling it over.  There's at least one place I know where
it would be useful.  Consider when you have an attribute which
is the same as a Python reserved word, like print.  (This happens
with interfaces to libraries written in other languages.)
  x.print
will fail.  The normal workaround is to append an '_', as in
  x.print_
This proposal would instead allow it to work as
  x.'print'

Hmm.  Would x.'a' 'b' 'c' be the same as x.'abc'?  Yeah,
I guess so.

BTW, in the 4 years I've been reading this group I don't think
I've seen this proposal come up.  I'm glad you didn't mention
(fill-in-suggestion-which-I-won't-mention-for-fear-of-a-two-
week-long-rehash-of-threads-hashed-to-death-years-ago :)

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list