Why not 3.__class__ ?

John Roth johnroth at ameritech.net
Wed Oct 10 18:07:27 EDT 2001


"Andrew Dalke" <dalke at dalkescientific.com> wrote in message
news:9q20bh$mjs$1 at slb3.atl.mindspring.net...
> Michael Abbott wrote:
> >More to the point, I don't see any room for any
> >bugs at all here (let alone obscure ones), since the offending syntax is
> >caught by the "compiler".
>
> Suppose there's an attribute named 'j'.  Under current Python
>
> >>> 3.j
> 3j
> >>> 3. j
>   File "<stdin>", line 1
>     3. j
>        ^
> SyntaxError: invalid syntax
> >>>

I posted before I saw Tim Peters' comments  in another branch of this
thread. It turns out that
"3.j" generates a syntax error,

as does "3. j"

However, "3 .j" and "3 . j" both generate an attribute error, because
the object '3' does not have an attribute 'j'.

Tim has already said that this is not going to change, and I really
don't see any overwhelming need for it to change.

I still consider it a wart, but its a wart that is inherited from a
long line of predecessors, going back at least to Pascal. I suppose
it's a special case of the "maximum munch" rule, and needs to
be taught to students.

I presume (although I haven't tested it) that "3(x, y, z)" produces a
"not callable object" error, and "3[x]" produces a "not subscriptable"
error as well. I really can't see what calling '3' would do, but
subscripting '3' might be a neat way of getting the bit representation.

John Roth







More information about the Python-list mailing list