Nick Coghlan wrote:
Michael Foord wrote:
Fred Mailhot wrote:
Hi,
It is stated in PEP 257 that:
"The docstring of a script (a stand-alone program) should be usable as
its "usage" message, printed when the script is invoked with incorrect
or missing arguments (or perhaps with a "-h" option, for "help").[...]"
I wasn't aware of that advice. Hmmm...
Anway - how about this:
import sys
module = sys.modules['__main__'] # or [__name__]
docstring = module.__doc__
No need for the fancy footwork - remember that a module's globals and
its attributes are the same dict:
~/devel$ cat > demo.py
"My docstring"
print __doc__
Ha! :-)
Thanks
Michael
~/devel$ python demo.py
My docstring
For modules and classes, the interpreter sets "__doc__" in the current
namespace automatically when it builds the docstring (not functions
though - their docstring isn't added to the local scope).
Cheers,
Nick.
--
http://www.ironpythoninaction.com/
_______________________________________________
Doc-SIG maillist - Doc-SIG@python.org
http://mail.python.org/mailman/listinfo/doc-sig