deleter — Python Reference (The Right Way) 0.1 documentation

文章推薦指數: 80 %
投票人數:10人

A property object has getter, setter, and deleter methods usable as decorators that create a copy of the property with the corresponding accessor function ... PythonReference(TheRightWay) latest Introduction Definitions CodingGuidelines FundamentalDataTypes Built-InFunctions ComprehensionsandGeneratorExpression ContainerDataAccess Operators Statements OtherObjects DoubleUnderscoreMethodsandVariables Exceptions Constants Boilerplate GlimpseofthePSL Resources Licence PythonReference(TheRightWay) Docs» deleter EditonGitHub deleter¶ Description¶ Overridesattributeaccessmechanism. Syntax¶ property.getter(method) method Amethodtodecorate. ReturnValue¶ None TimeComplexity¶ #TODO Remarks¶ Apropertyobjecthasgetter,setter,anddeletermethodsusableasdecoratorsthatcreateacopyofthepropertywiththecorrespondingaccessorfunctionsettothedecoratedfunction.Thisisbestexplainedwithanexample: classC(object): def__init__(self): self._x=None @property defx(self): """I'mthe'x'property.""" returnself._x @x.setter defx(self,value): self._x=value @x.deleter defx(self): delself._x Thiscodeisexactlyequivalenttothefirstexample.Besuretogivetheadditionalfunctionsthesamenameastheoriginalproperty(xinthiscase.) Thereturnedpropertyalsohastheattributesfget,fset,andfdelcorrespondingtotheconstructorarguments. Example¶ >>>foo 3.6055512754639896 ReadtheDocs v:latest Versions latest Downloads pdf htmlzip epub OnReadtheDocs ProjectHome Builds FreedocumenthostingprovidedbyReadtheDocs.



請為這篇文章評分?