property() type that only protects set?

Brad Clements bkc at Murkworks.com
Tue Apr 9 17:17:42 EDT 2002


If you leave out fget (that is, let it default to None) then you have an
attribute that cannot be read.

This isn't what I want.. I want an attr that can be read without a special
getter function

(something like

myprop = property(self.__getattr,my_set)

But of course this syntax doesn't work.



--
Novell DeveloperNet Sysop #5

_
"Neal Norwitz" <neal at metaslash.com> wrote in message
news:3CB357E3.95EFC8E1 at metaslash.com...
> Brad Clements wrote:
> >
> > Anyone have an implementation of property() that doesn't require a
getter,
> > only a setter (and optional del)
> >
> > I only need to protect set operations, and want to allow get to go
straight
> > to __dict__
> >
> > (or object when I'm using slots)
>
> From the docstring:
>
> >>> print property.__doc__
> property(fget=None, fset=None, fdel=None, doc=None) -> property attribute
>
> fget is a function to be used for getting an attribute value, and likewise
> fset is a function for setting, and fdel a function for del'ing, an
> attribute.  Typical use is to define a managed attribute x:
> class C(object):
>     def getx(self): return self.__x
>     def setx(self, value): self.__x = value
>     def delx(self): del self.__x
>     x = property(getx, setx, delx, "I'm the 'x' property.")
> --------------------------------------------------------------------------
--
>
> so use:
>
>     x = property(fset=setx)
>
> Neal




-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----



More information about the Python-list mailing list