Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The text that is used for "help" is indeed the "<code>__doc__</code>" attribute of an object. The matter is that depending on the object you have, you can't simply set the <code>__doc__</code> attribute on it.</p> <p>If what you need is "<code>help(object.attr)</code>" to work (and not that <code>help(object)</code> shows you all possible attributes) it is a bit easier - you should only get shure that whatever <code>__getattr__</code> returns do hae a properly set docstring.</p> <p>SInce "it is not working" I'd guess you are returning the internal results of some function call, like in this snippet:</p> <pre><code>def __getattr__(self, attr): if attr == "foo": #function "foo" returns an integer return foo() ... </code></pre> <p>If you simply would return the function "foo" itself, without calling it, itś docstring would be displayed normally.</p> <p>What can be done is to wrap the return value in <code>__getattr__</code> as an object of a dynamically created class wich contains a proper docstring - so, try using somethong like this:</p> <pre><code>def __getattr__(self, attr): if attr == "foo": #function "foo" returns an (whatever object) result = foo() res_type = type(result) wrapper_dict = res_type.__dict__.copy() wrapper_dict["__doc__"] = foo.__doc__ #(or "&lt;desired documentation for this attribute&gt;") new_type = type(res_type.__name__, (res_type,), wrapper_dict) # I will leave it as an "exercise for the reader" if the # constructor of the returned object can't take an object # of the same instance (python native data types, like int, float, list, can) new_result = new_type(result) elif ...: ... return new_result </code></pre> <p>This should work - unless I got wrong the motive why hel is not working in the first place - if that is the case, please give some example of what you are returning from <code>__getattr__</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload