Why the property doc function does not display help information when it is called using help (instance.attribute)

class MyClass(object): def __init__(self): self._my_secret_thing = 1 def _i_get(self): return self._my_secret_thing def _i_set(self, value): self._my_secret_thing = value def _i_delete(self): del self._my_secret_thing my_thing = property(_i_get, _i_set, _i_delete,'this document for my_thing') instance_of = MyClass() help(instance_of.my_thing) # not display the 'this document for my_thing' help(instance_of) # display the 'this document for my_thing' 

Question Why is the help message for my_thing not displayed if it is called via help(instance_of.mything) ?

Python.property link

+4
source share
1 answer

When you access instance_of.my_thing , it returns a value - and therefore, in fact, you are calling help on - this is a value of 1 , not a property.

If you get access to the class object, and not to the instance, you will get a property object, and a docstring will be attached to it; i.e. use help(MyClass.my_thing) or help(type(instance_of).my_thing) .

+6
source

Source: https://habr.com/ru/post/1397030/


All Articles