[Tutor] Viewing __doc__ strings
Remco Gerlich
scarblac@pino.selwerd.nl
Fri, 8 Jun 2001 16:55:14 +0200
On 0, Allan Crooks <amc1@dcs.qmw.ac.uk> wrote:
> Is there anyway to make Python display __doc__ strings without all the
> "\n" characters? I know I could manually split it and then rejoin it, but
> surely there's an easier way?
print it:
>>> len.__doc__
'len(object) -> integer\n\nReturn the number of items of a sequence or mapping.'
>>> print len.__doc__
len(object) -> integer
Return the number of items of a sequence or mapping.
Just like any other strings with \n's in them, really :)
Personally I use a little doc() function that goes like this:
def doc(x):
print "Object:", `x`
print
if hasattr(x, '__doc__'):
print "Docstring:"
print x.__doc__
else:
print "No docstring."
So I can just type
>>> doc(object)
> I'm using Python 2.1 on WinNT 4, if that's of any use.
On Linux I put that function in ~/.pythonrc, but I don't know where it goes
on WinNT. There should be a file that's executed before you enter the
interpreter.
--
Remco Gerlich