Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: How to use the docstring in this property example Date: Thu, 21 Jan 2016 18:15:09 +0100 Organization: None Lines: 54 Message-ID: References: <1cb14a23-9fe4-44e4-ae25-e894852b245c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de tm8LU2hYR1ZxH66ZWHtvYgYJMoynLxtrqmpBpgUbsozQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'that?': 0.05; 'skip:/ 10': 0.07; 'subject:How': 0.09; 'attribute.': 0.09; 'given,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'snippet': 0.09; 'def': 0.13; 'descriptors': 0.16; 'docstring': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'doc': 0.22; 'defined': 0.23; 'module': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'invoke': 0.29; "i'm": 0.30; 'code': 0.30; 'skip:_ 10': 0.32; 'class': 0.33; 'url:python': 0.33; 'usually': 0.33; 'skip:- 10': 0.34; 'could': 0.35; 'instance': 0.35; 'robert': 0.35; 'subject:use': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'hi,': 0.38; 'data': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; "you'll": 0.61; 'show': 0.62; 'here:': 0.63; 'link:': 0.69; 'object:': 0.84; 'url:functions': 0.84; 'subject:this': 0.85 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd8cd0.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101984 Robert wrote: > Hi, > > I read below code snippet on link: > https://docs.python.org/2/library/functions.html#property > > -------------- > class C(object): > def __init__(self): > self._x = None > > 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.") > If c is an instance of C, c.x will invoke the getter, c.x = value will > invoke the setter and del c.x the deleter. > > If given, doc will be the docstring of the property attribute. > //////////////// > > I can use these: > c.x > c.x=42 > del c.x > > but I don't know how to get the doctring from the property attribute. > Could you show me how to do that? >>> c = C() >>> type(c).x.__doc__ "I'm the 'x' property." But usually you'll see it as part of the help on c: >>> help(c) Help on C in module __main__ object: class C(__builtin__.object) [...] | Data descriptors defined here: [...] | x | I'm the 'x' property.