[Python-Dev] a quit that actually quits

Fernando Perez fperez.net at gmail.com
Thu Dec 29 17:50:19 CET 2005


Fredrik Lundh wrote:

> Fernando Perez wrote:
> 
>> In [1]: x='hello'
>>
>> In [2]: x?
> /.../
>> Docstring:
>>     str(object) -> string
>>
>>     Return a nice string representation of the object.
>>     If the argument is a string, the return value is the same object.
> 
> I'm not sure what I find more confusing: a help system that claims that
> the variable x returns a nice string representation of an object, or that
> there's no help to be found for "hello".

Then, complain about docstrings:

Python 2.3.4 (#1, Feb  2 2005, 12:11:53)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x='hello'
>>> print x.__doc__
str(object) -> string

Return a nice string representation of the object.
If the argument is a string, the return value is the same object.

====

In ipython, '?' does the best it can to collect information about an object,
making heavy use of python's introspection capabilities.  It provides class and
constructor docstrings, function call signatures (built from the function code
object), and more.  Using ?? gives even more details, including
syntax-highlighted source when available.  For example:

In [5]: pydoc.ErrorDuringImport??
Type:           classobj
String Form:    pydoc.ErrorDuringImport
Namespace:      Interactive
File:           /usr/lib/python2.3/pydoc.py
Source:
class ErrorDuringImport(Exception):
    """Errors that occurred while trying to import something to document it."""
    def __init__(self, filename, (exc, value, tb)):
        self.filename = filename
        self.exc = exc
        self.value = value
        self.tb = tb

    def __str__(self):
        exc = self.exc
        if type(exc) is types.ClassType:
            exc = exc.__name__
        return 'problem in %s - %s: %s' % (self.filename, exc, self.value)
Constructor information:
Definition:     pydoc.ErrorDuringImport(self, filename, (exc, value, tb))


I'm sorry it can't provide the information you'd like to see.  It is still found
to be useful by many people, including myself.  You are welcome to use it, and
patches to improve it will be well received.

Best,

f



More information about the Python-Dev mailing list