[Tutor] Viewing __doc__ strings
Patrick K. O'Brien
pobrien@orbtech.com
Fri, 8 Jun 2001 10:54:11 -0500
I like that a lot. Very helpful when you are messing with something new in
interactive mode. You inspired me to create my own variation. Hope everyone
likes it.
def doc(x):
"""Print type, representation and documentation string for object x."""
print "Object:", str(x)
print "Object Type:", type(x)
print "Representation:", repr(x)
print "Documentation String:"
print "---------------------"
try:
print x.__doc__
except AttributeError:
print "This object does not have a documentation string."
---
Patrick K. O'Brien
Orbtech
"I am, therefore I think."
-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Remco Gerlich
Sent: Friday, June 08, 2001 9:55 AM
To: tutor@python.org
Subject: Re: [Tutor] Viewing __doc__ strings
<snip>
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
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor