1

I would like to know the what are the methods and properties in the object class of Python but I can't find the documentation anywhere. Do you guys know where can I find it?

1
  • 1
    You can also use ipython with its awesome tab completion. Commented Jul 31, 2017 at 22:18

1 Answer 1

3

You can use dir to list them:

>>> dir(object)
['__class__',
 '__delattr__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__']

Be warned that an object can lie about what attributes are there. For example, object.mro exists but the dir chooses not to tell you about it.

To find an "uncensored" list, try this:

>>> object.__dir__(object)
Sign up to request clarification or add additional context in comments.

3 Comments

dir() doesn't show methods provided by type, the metaclass of object. object.mro is really type.mro.
As for object.__dir__() vs. dir(), the latter calls type.__dir__(object), while object.__dir__() is meant for instances (so used for dir(instance)). The latter also looks at type(instance), while the former does not, which is why the object.__dir__(object) list is larger. You basically have the same output as list(set(dir(object)).union(dir(type))) (modulus ordering).
As documented in the link provided. Note Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. For example, metaclass attributes are not in the result list when the argument is a class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.