Python language suggestion

Chris Ryland cpr at emsoftware.com
Sat Jan 13 18:44:46 EST 2001


From: "Moshe Zadka" <moshez at zadka.site.co.il>


> On Thu, 11 Jan 2001 20:27:39 GMT, Chris Ryland <cpr at emsoftware.com> wrote:
> > This migh sound radical, but has anyone ever entertained the idea that
> > foo.'bar bletch' might be a useful and logical extension of Python's
> > current attribute selection machinery?
> >
> > I realize that foo['bar bletch'] is just as good for dictionary-like
> > objects, but foo.'bar bletch'
>
> getattr(foo, 'bar bletch') works in Python.

Actually, this brings up an interesting point.

Why doesn't the attribute reference (primary "." identifier) work for any
dictionary-like object?

E.g., why doesn't

f = {'a': 1, 'b': 2}
print f.a

work while

f['a']

does? (I mean from a language design standpoint, not why doesn't it work
currently.)

It seems like the attribute reference should work on any dictionary-like
object, whether built-in (actual dictionary), module, or instance. That
would seem more Pythonic (fewer special cases).

(And then it's an easy step to

f = {'foo bar': 1, 'bletch': 2}
f.'foo bar'

;-)

Cheers!
Chris Ryland, President * Em Software, Inc. * www.emsoftware.com





More information about the Python-list mailing list