How to access the document for __call__ from command line?

Terry Reedy tjreedy at udel.edu
Thu Oct 18 22:59:13 EDT 2012


On 10/18/2012 10:30 PM, Peng Yu wrote:
> Hi,
>
> reference.pdf from python document has the following description. It
> is not accessible from help() in the command line. Is there an
> alternative so that I can quickly access these class attributes or
> method names from the command line?
>
> object.__call__(self [, args... ])
> Called when the instance is “called” as a function; if this method is
> defined, x(arg1, arg2, ...) is a
> shorthand for x.__call__(arg1, arg2, ...).

 >>> help(object.__call__)
Help on method-wrapper object:

__call__ = class method-wrapper(object)
  |  Methods defined here:
  |
  |  __call__(...)
  |      x.__call__(...) <==> x(...)
  |
snip not very helpful stuff

For a user class with a __call__ method with a docstring

 >>> class C:
	def __call__(self, x):
		"return the difference between self and x"
		return self-x

 >>> help(C.__call__)
Help on function __call__ in module __main__:

__call__(self, x)
     return the difference between self and x

Similarly for builtin methods you actually need to know about

 >>> help(list.append)
Help on method_descriptor:

append(...)
     L.append(object) -> None -- append object to end



-- 
Terry Jan Reedy





More information about the Python-list mailing list