Module access from inside itself
just at xs4all.nl
Fri Aug 15 20:01:42 CEST 2003
In article <pan.2003.08.16.02.34.37.555746.14368 at mikka.net.au>,
Steven <dippy at mikka.net.au> 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:
> """Module doc string goes here.
> import getopt, sys
> def MyFunction(args):
> 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?
> 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