[Python-ideas] Write-only property [was Re: The AttributeError/__getattr__ mechanism]

Steven D'Aprano steve at pearwood.info
Mon Nov 30 12:08:12 EST 2015


On Mon, Nov 30, 2015 at 08:07:14AM -0800, Andrew Barnert wrote:
> On Nov 30, 2015, at 02:32, Steven D'Aprano <steve at pearwood.info> wrote:
> > 
> >> On Sun, Nov 29, 2015 at 11:31:14AM -0800, Andrew Barnert via Python-ideas wrote:
> >> 
> >> (How would you implement a write-only property 
> >> that makes "print(spam.eggs)" raise an AttributeError except by 
> >> raising it in the property function?)
> > 
> > eggs = property(None, setter, None, "")
> > 
> > makes eggs a write-only property. print(spam.eggs) gives 
> > 
> > AttributeError: unreadable attribute
> 
> And how do you think property implements that? 

Sorry, I misunderstood your (rhetorical?) question -- I read it as 
implying one should explicitly write a getter which raised 
AttributeError.



-- 
Steve


More information about the Python-ideas mailing list