Hi,<br><br>It is stated in PEP 257 that:<br><br>"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").[...]"<br><br>This is exactly what I'm trying to do, but I haven't been able to figure out how to access a script's docstring from within it. That is, I'm assuming (perhaps erroneously) that I can define some kind of usage function in my script that will spit out the docstring, as in the following example<br>
<br>#!/usr/bin/python<br>""" <br>myscript.py<br><br>Usage: python myscript.py <params><br><br>Some more specific info here.<br>"""<br><br>[python code here]<br><br>def main():<br> [do stuff here]<br>
<br>### THIS IS WHAT I'D LIKE TO DO... ###<br>def usage():<br> sys.stderr.write(this.__doc__)<br> sys.exit()<br>### EXCEPT OF COURSE "this" ISN'T DEFINED<br><br>if __name__ == "__main__":<br>
if [some condition is not satisfied]:<br> usage()<br> else:<br> main()<br>################################<br><br>What should I be doing instead? I've Googled a bunch and turned up nothing, so I may just not be looking for the right terms (Googling "python print script docstring" gets me nothing).<br>
<br>Thanks!<br>Fred.<br><br>