Good day!
I’m writing a little tool that builds a GUI for my data-aware app.
The basic idea is to get a module containing a model description (sqla/elixir entities) as an input, and to present the user with a list of available classes (inherited from Entity()) and their fields (inherited from Field()) from this module.
The pyclbr module is fine for getting classes and their methods, but it can’t read other class-members. I know about __dict__ and inspect module, but the problem is they require instantiation of a class in question, and that is kind of wrong in this context. So, is there another way ?
I really don’t want to parse modules as text. 🙂
I’m not sure I know what you mean:
prints
You can use
if you don’t want to see the special methods.
You don’t need to instantiate the class to see it’s members. You won’t see attributes added inside methods, but everything defined in the class definition or a metaclass’
__new__method will be there.See my answer to inspect.getmembers() vs __dict__.items() vs dir() for more info on what exactly these different functions return.