Immutability

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Wed Jun 28 12:46:31 EDT 2006


Nick Maclaren schreef:
> 
> Most especially since it isn't working very well for me, and I am trying
> to track down why.  When I run:
> class fred :
>     @property
>     def joe (self) :
>         print "Inside /joe\n"
> 
> a = fred()
> a.joe()
> 
> I get:
> 
> Inside joe
> 
> Traceback (most recent call last):
>   File "crap.py", line 14, in <module>
>     a.joe()
> TypeError: 'NoneType' object is not callable

Since joe is a property, you shouldn't access it as a method. This works:

a = fred()
a.joe

Inside joe


If you call it as a function, first the function is executed (printing 
"Inside joe"), but then Python tries to call the return value of the 
function, which is None.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Python-list mailing list