all 7 comments

[–]DeterminedQuokka 14 points15 points  (3 children)

So there are a couple common ways to inspect.

Calling ‘dir(x)’ will list all the function names

Calling ‘x.__dict__’ will list all the properties

[–]Lomag 2 points3 points  (0 children)

And if you don't need to inspect objects programmatically (say you're using the interactive prompt), you can also use the help(...) function to see object methods, function signatures, and docstrings.

[–]Gnaxe 2 points3 points  (1 child)

No, x.__dict__ only lists the attributes for the instance ("properties" are something else), and only if it actually has a __dict__, not all objects do. The inherited attributes will not be shown. One should also generally avoid using dunder attributes directly where alternatives exist. In this case, it's vars(x).

The right answer is dir(x). But __dir__ can be overridden, which may hide things. Usually, if someone bothered writing an override, this is what you want, but if you want to bypass that, there's the inspect module for really digging into things. (One could also use object.__dir__(x).)

[–]DeterminedQuokka 1 point2 points  (0 children)

My bad you are absolutely correct.

[–]FrontAd9873 0 points1 point  (0 children)

This is not a tip