Python Forum

Full Version: what is the doc parameter of property?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all.

I was doing some light reading and noticed a line in sprite.py file that I didn't totally understand. The lines of code were found in the DirtySprite class. I guess its declaring a property in the sprite module for the class DirtySprite, but I thought all declarators like that had to be declared like:
@property
The lines i'm interested in are:
visible = property(lambda self: self._get_visible(),
                       lambda self, value: self._set_visible(value),
                       doc="you can make this sprite disappear without "
                           "removing it from the group,\n"
                           "assign 0 for invisible and 1 for visible")
Can anyone tell me anything about the doc parameter? Think

FYI: I'm running a RaspberryPi2B+
See python docs https://docs.python.org/3/library/functi...y#property
doc creates a docstring for the attribute.

visible = property(lambda self: self._get_visible(),
                       lambda self, value: self._set_visible(value),
                       doc="you can make this sprite disappear without "
                           "removing it from the group,\n"
                           "assign 0 for invisible and 1 for visible")

help(visible)
Output:
Help on property: you can make this sprite disappear without removing it from the group, assign 0 for invisible and 1 for visible
we could go inception and use property's doc string to find out what the doc of property is.
help(property)
Output:
class property(object) | property(fget=None, fset=None, fdel=None, doc=None) | | Property attribute. | | fget | function to be used for getting an attribute value | fset | function to be used for setting an attribute value | fdel | function to be used for del'ing an attribute | doc | docstring | | 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.") | | Decorators make defining new properties or modifying existing ones easy: | | class C(object): | @property | def x(self): | "I am the 'x' property." | return self._x | @x.setter | def x(self, value): | self._x = value | @x.deleter | def x(self): | del self._x | | Methods defined here: | | __delete__(self, instance, /) | Delete an attribute of instance. | | __get__(self, instance, owner, /) | Return an attribute of instance, which is of type owner. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | __set__(self, instance, value, /) | Set an attribute of instance to value. | | deleter(...) | Descriptor to change the deleter on a property. | | getter(...) | Descriptor to change the getter on a property. | | setter(...) | Descriptor to change the setter on a property. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __isabstractmethod__ | | fdel | | fget | | fset
I've been following up the help you've given so far, and found a style of doc string that I would like to apply to my code, Numpy.

Thanks for the help. I never thought of using the "help" function on my own code before , a nice eye opener. Shocked This looks really useful.