views:

60

answers:

2

Hello guys,

I would like to do something like this :

def main():
    """
    Display Information about a Google Calendar

     -u --user login     Google Login
     -p --pass password  Google Password
     -d --debug          Set DEBUG = True
     -h --help           Display this help
    """

    print(__doc__)

if __name__ == "__main__":
    main()

But the answer is : None ... Why ?

+3  A: 

Because __doc__ is an attribute of the function, not a local variable. You need to refer to it as main.__doc__ like this:

def main():
    """Display Information about a Google Calendar

    ..."""
    print(main.__doc__)

if __name__ == "__main__":
    main()
intgr
Of-course it is that simple ...
Natim
+2  A: 

If the help that you want to print is "global", you might find it more logical to put it as the main documentation for your program:

#!/usr/bin/env python
"""
Display Information about a Google Calendar
...
"""

if __name__ == '__main__':
    print __doc__

__doc__ is a global variable that contains the documentation string of your script.

EOL
Ok, now I see the difference, but what is the best todo ?
Natim
@Natim What do you want `pydoc my_prog` to display? If you want it to first display the documentation for your program as a whole, it's simpler to use the *global* doc string. If you don't to that, the reader has to guess that the doc for main() is the doc for your program.
EOL
Ok, it makes senses.
Natim