![]() |
printing main doc - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: printing main doc (/thread-11189.html) |
printing main doc - bluefrog - Jun-27-2018 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 testHow do I print the main doc out? RE: printing main doc - gontajones - Jun-27-2018 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. |