Get __doc__ from main module in imported module.

David davidism at gmail.com
Thu Feb 11 01:48:39 CET 2010


I have a module toolkit.py with some functions I use often.  One of
these functions displays a usage message (__doc__).

def usage(messages=[], exit=-1):
    """Print the doc string as wells as any useful messages."""
    print(__doc__)
    for message in messages:
        print("\033[91m{}\033[0m".format(message))
    if exit >= 0:
        sys.exit(exit)

I import this module into another module, with the doc string I want
to display.  However, calling usage prints toolkit's doc string
(None), not the current module's doc string.

How can I access the top level module's doc string from toolkit?



More information about the Python-list mailing list