Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101984
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How to use the docstring in this property example |
| Date | 2016-01-21 18:15 +0100 |
| Organization | None |
| Message-ID | <mailman.154.1453396521.15297.python-list@python.org> (permalink) |
| References | <1cb14a23-9fe4-44e4-ae25-e894852b245c@googlegroups.com> |
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How to use the docstring in this property example Robert <rxjwg98@gmail.com> - 2016-01-20 20:00 -0800 Re: How to use the docstring in this property example Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-01-21 15:50 +1100 Re: How to use the docstring in this property example Peter Otten <__peter__@web.de> - 2016-01-21 18:15 +0100
csiph-web