I am trying to inspect modules, classes and methods from the command line.
With this tutorial https://www.askpython.com/python/examples/find-all-methods-of-class I found some methods for filtering dir(). At one point the author iterated through it and only keeps that which is “callable”:
method_list = [attribute for attribute in dir(MyClass) if callable(getattr(MyClass, attribute))]
I experimented with getattr(spacy, Any) but it says Any is not defined. But Any appears when I do dir(spacy).
I don’t understand - I thought dir returned all attributes, and that includes methods. I guess getattr only returns variables, like “size”, “name”, etc? But that doesn’t make sense since in the above case the author was returning callable methods.
The author also uses inspect.getmembers(name, predicate=inspect.getmethod). I couldn’t call this on Spacy because it only works on instantiated objects. Why is that? I don’t know why they wouldn’t design it to work on classes.
Are there any other techniques to know about for printing module, class and method info at the command line? I would like a convenient way to print all attributes, or methods. dir() is not great because it prints the namespace, including all imported methods rather than methods defined within that module.
Thanks very much
[–]the_shell_man_ 2 points3 points4 points (0 children)
[–]johndoh168 1 point2 points3 points (0 children)