2

As we can see here: http://docs.python.org/2/library/functions.html#object

Return a new featureless object. object is a base for all new style classes. It has the methods that are common to all instances of new style classes.

What methods specifically according to this? Where is the reference?

1
  • 1
    execute dir(object) Commented Mar 12, 2014 at 8:18

2 Answers 2

2

Use the dir() function to inspect a class or object:

>>> dir(object)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', 
 '__hash__',  '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
 '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

See also the Python Language Reference, which can be searched to find details on each of these special methods.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but do we have an API reference which will describe what each function will do, like many other languages?
There's some info on these methods in the Language Reference, though not specifically for object. The language reference is searchable though, so you should be able to find all of the methods returned by dir()
An easy to follow guide to supplement the documentation: rafekettler.com/magicmethods.html
1

do we have an API reference which will describe what each function will do, like many other languages?

Apart from reading the python docs/tutorials, you can use help to see the docstring of the methods/functions

In [443]: help(object.__hash__)
Help on wrapper_descriptor:

__hash__(...)
    x.__hash__() <==> hash(x)

If you're using the ipython interactive shell, simply use ? instead of help function:

In [446]: object.__hash__?
Type:       wrapper_descriptor
String Form:<slot wrapper '__hash__' of 'object' objects>
Namespace:  Python builtin
Docstring:  x.__hash__() <==> hash(x)

You can even use ?? to access the source of a function, e.g.:

In [454]: os.path.getsize??
Type:       function
String Form:<function getsize at 0x01C6DEF0>
File:       d:\anaconda\lib\genericpath.py
Definition: os.path.getsize(filename)
Source:
def getsize(filename):
    """Return the size of a file, reported by os.stat()."""
    return os.stat(filename).st_size

In [455]: 

Comments

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.