Immutability

Bruno Desthuilliers onurb at xiludom.gro
Wed Jun 28 12:07:49 EDT 2006


Nick Maclaren wrote:
> 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"


properties dont work properly on old-style classes (lookup 'new-style
classes' on python.org, in the documentation menu), hence the strange
behaviour you observe. Retry the same thing with s/class fred/class
fred(object)/


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list