Immutability

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Jun 28 11:20:23 EDT 2006


In article <4Qj*cEjkr at news.chiark.greenend.org.uk>,
Sion Arrowsmith <siona at chiark.greenend.org.uk> writes:
|> 
|> Actually, there's an almost throw-away mention in
|> http://docs.python.org/ref/descriptor-invocation.html
|> which gives you what you need (although not, I have to say, in an
|> easily digestible form).

Thanks very much.

|> What I've not seen documented anywhere is the:
|>         @property
|>         def fset(self, value):
|>             ...
|> idiom. It's not obvious from the documentation of the property
|> function that it can be used as a decorator like this. (cf.
|> classmethod and staticmethod.)

Most especially since it isn't working very well for me, and I am trying
to track down why.  When I run:

class alf :
    def pete (self) :
        print "Inside pete\n"

b = alf()
b.pete()

class fred :
    @property
    def joe (self) :
        print "Inside /joe\n"

a = fred()
a.joe()

I get:

Inside pete

Inside joe

Traceback (most recent call last):
  File "crap.py", line 14, in <module>
    a.joe()
TypeError: 'NoneType' object is not callable

VERY weird - I could understand it if I got the error and DIDN'T succeed
in the call ....
Regards,
Nick Maclaren.



More information about the Python-list mailing list