Module access from inside itself

Just just at
Fri Aug 15 20:01:42 CEST 2003

In article <pan.2003. at>,
 Steven <dippy at> wrote:

> 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?

You can just access __doc__ directly. No module prefix neccesary.


More information about the Python-list mailing list