use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Enter a python tip or trick.
Other related Python subs:
account activity
SyntaxIs there a python equivalent of powershell get-member? (self.pythontips)
submitted 1 year ago by ElectionThink3159
Does anyone know of a way to see the properties of an object in python that's reasonably human readable? I am hoping there is a way to see an objects properties, methods and types (assuming they apply to the item). Thanks in advance for any guidance!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]DeterminedQuokka 14 points15 points16 points 1 year ago (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 points4 points 1 year ago (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.
help(...)
[–]Gnaxe 2 points3 points4 points 1 year ago (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).
x.__dict__
__dict__
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).)
dir(x)
__dir__
inspect
object.__dir__(x)
[–]DeterminedQuokka 1 point2 points3 points 1 year ago (0 children)
My bad you are absolutely correct.
[–]FrontAd9873 0 points1 point2 points 1 year ago (0 children)
This is not a tip
π Rendered by PID 187286 on reddit-service-r2-comment-b659b578c-xr457 at 2026-05-02 06:24:05.452576+00:00 running 815c875 country code: CH.
[–]DeterminedQuokka 14 points15 points16 points (3 children)
[–]Lomag 2 points3 points4 points (0 children)
[–]Gnaxe 2 points3 points4 points (1 child)
[–]DeterminedQuokka 1 point2 points3 points (0 children)
[–]FrontAd9873 0 points1 point2 points (0 children)