Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing main doc
#1
I have a doc declared at the top of a script, like so:

#!/usr/bin/python3
import re
"""
A Twitter username can only contain alphanumeric characters (A-Z numbers 0-9).
The exception being an underscore. Symbols, dashes or spaces are not valid.
Examples:
@zyx - valid
@xyz_abc - valid, since it contains an underscore
@abc!abc - invalid, since it contains  a special character
xyz@abc - invalid, since characters that prefix the @ are not allowed
@999 - valid
@abc 999 - invalid, since spaces cannot form part of the username
"""

def test_doc():
  """ This is a test """

if __name__ == "__main__":
  print(__doc__)
  #  print(main.__doc__)
  print(test_doc.__doc__)
Output:
None
 This is a test 
How do I print the main doc out?
Reply
#2
Docstring must be before the imports:

#!/usr/bin/python3
"""
A Twitter username can only contain alphanumeric characters (A-Z numbers 0-9).
The exception being an underscore. Symbols, dashes or spaces are not valid.
Examples:
@zyx - valid
@xyz_abc - valid, since it contains an underscore
@abc!abc - invalid, since it contains  a special character
xyz@abc - invalid, since characters that prefix the @ are not allowed
@999 - valid
@abc 999 - invalid, since spaces cannot form part of the username
"""

import re


def test_doc():
  """ This is a test """
 
if __name__ == "__main__":
  print(__doc__)
  #  print(main.__doc__)
  print(test_doc.__doc__)
From Imports
Quote:Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm having trouble printing a return value in my main function RedSkeleton007 2 3,097 Apr-08-2018, 04:17 PM
Last Post: IAMK

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020