Distinguishing attributes and methods

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sun Dec 9 08:13:01 EST 2007


Roy Smith a écrit :
> In article <475b17dc$0$31712$426a74cc at news.free.fr>,
>  Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> wrote:
> 
> 
>>MonkeeSage a écrit :
(snip)
>>>Bah. Type-by-behavior never impressed me much. And I still think that
>>>a.a is semantically different from a.a() in python.
>>
>>It is indeed and very obviously semantically different, and no one said 
>>it wasn't. The first is an attribute lookup, the second is an attribute 
>>lookup followed by a call. Now this doesn't make the attribute lookup 
>>part different in both cases...
> 
> 
> There are a very few corner cases were you can leave the ()'s out.

You can leave them out wherever you want - it's just that it won't do 
the same thing !-)

>  For 
> example, you can do;
> 
> raise Exception
> 
> or
> 
> raise Exception()

The context is somewhat different...

> but stuff like that is very much a wart in the language syntax.

The syntax is

   raise [<expression>[, <expression>,[ <expression>]]]

which can be used as either

   raise <type>[, <value>[, <traceback>]]

or

   raise <instance>[, None[, <traceback>]]


http://docs.python.org/ref/raise.html

You can call it a wart, but at least it's a well defined one - that is, 
the first expression must eval to either an Exception type or an 
Exception instance. So the 'optional' use of the call operator here has 
nothing to do with it's mandatory use to actually call a function.



More information about the Python-list mailing list