Module access from inside itself

Steven dippy at mikka.net.au
Fri Aug 15 12:20:43 EDT 2003


I'm writing a Python script which can be called from the command-line, and 
I want to use my module doc string as the CL help text, but I don't know 
how to access my module object from inside the module.

I've tried searching for an answer, but haven't found anything. Please
excuse me if I'm missing something simple, I'm a newbie to Python.

I'm doing something like this:



#!/usr/bin/python
"""Module doc string goes here.
"""

import getopt, sys

def MyFunction(args):
    pass

if __name__ == "__main__":
    opts, args = getop.getopt(sys.argv[1:], [], ["help"])
    for opt in opts:
        if opt == "--help":
            print MY_MODULE.__doc__    # How do I get this?
        else:
            MyFunction(args)



How do I get a reference to the module from inside the module? Is this
the Pythonic way of generating help strings for CL scripts?


Thanks,


-- 
Steven D'Aprano




More information about the Python-list mailing list