Python language suggestion

Peter Hansen peter at engcorp.com
Sun Jan 14 01:22:58 EST 2001


Chris Ryland wrote:
> 
> 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.)

IMHO, your whole suggestion about x.'name' being treated 
as x.name is ill-conceived.

In the specific case you identify above, what do you 
intend to do about the following?

>>> f = { 'a' : 5, 'b' : 6 }
>>> a = 'b'
>>> f['a']
5
>>> f[a]
6
>>> f.a
5? 6? ??? help!!

That is, which should f.a return here, 5 or 6?  Why?
The point is, it's not intuitive, and is definitely
going to cause trouble for newbies, let alone 
experienced programmers.  This is a sure sign of a
Bad Idea.  Let it go.



More information about the Python-list mailing list