Display dynamically added methods and attributes in python help -
i have class add new methods , properties dynamically. new properties handled overriding __getattr__ , __setattr__ while new methods added directly (obj.mymethod = foo). there way make these show if "help(inst)" inst instance of class? right see methods , attributes have "hardcoded" in source. methods show if "dir(inst)".
the issue help(inst) provides information class instance "inst" derived from.
say obj derived class a, instead of doing obj.mymethod = foo, if did a.mymethod = foo, show in help(obj)
look @ example below , it's output.
class a(object): def __init__(self): pass def method1(self): "this method1 of class a" pass = a() help(a) def method2(self): """ method 2 still not associated""" pass a.method2 = method2 # if did a.method2 = method2 # won't show in help() statement below help(a)
as per documentation, if argument other kind of object, page on object generated. example above, see adding method in namespace of class shown in help() function if added method 1 instance of class, not show in help().
Comments
Post a Comment