Reputation: 22903
From Dive into Python:
Python has a function called info. Try it yourself and skim through the list now.
>>> from apihelper import info
>>> import __builtin__
>>> info(__builtin__, 20)
ArithmeticError Base class for arithmetic errors.
AssertionError Assertion failed.
AttributeError Attribute not found.
EOFError Read beyond end of file.
EnvironmentError Base class for I/O related errors.
Exception Common base class for all exceptions.
FloatingPointError Floating point operation failed.
IOError I/O operation failed.
It turns out that Python does not have a function called info. What was the book referring to?
Upvotes: 3
Views: 5470
Reputation: 813
Python don't have that module i.e. apihelper.py but diveintopython made that function in their tutorial
def info(object,spacing=10,collapse=1):
availableMethod = [method for method in dir(object) if callable(getattr(object,method))];
processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
print "\n".join(["%s %s" % (method.ljust(spacing),processFunc(getattr(object, method).__doc__)) for method in availableMethod])
This is the function they have developed, that what they are referring to its in the file apihelper.py that's why
from apihelper import info
hope it helps. :)
Upvotes: 0
Reputation: 2393
apihelper is a module from the book. You have to download it.
I found this link for this exemple and many others: http://www.diveintopython.net/download/diveintopython-examples-5.4.zip
Upvotes: 1
Reputation: 10360
I don't know why Dive Into Python claims that "Python has a function called info
", but it's obviously not true.
apihelper.py
(from which info
is imported) is described earlier in the book, in section 4.1, and is just a module that Mark Pilgrim wrote for use with Dive Into Python. That apihelper
module apparently does contain an info
function that does what is claimed in section 4.3.3, which you linked.
Upvotes: 6