Docstring
Format
  • The doc string line should begin with a capital letter and end with a period.
  • The first line should be a short description.
  • If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description.
  • The docstring may span multiple lines. The type may optionally be specified on the first line, separated by a colon.
  • Function or class function
  • Module
  • Class
  • #!/usr/bin/python
    '''A brief description of the module.
    
    Extended description.
    
    Example:
        python convert.py inputFile outputFile
    
    '''
    
    __author__ = "Lin Chen"
    __license__ = "GPL"
    __version__ = "0.1"
    __email__ = "lichen@valdosta.edu"
    __status__ = "Prototype"
    
    import sys, os # import built-in modules
    import bs4 # import third-party modules
    import m2 # import own modules
    
    def convertRead(filename):
        '''Summary line.
    
        Extended description.
    
        Args:
            filename (str): intput file name.
    
        Returns:
            list: a list of strings.
    
        Raises:
            IOError: io error.
    
        Examples:
            >>> l = convertRead('readme.txt');
    
        '''
        pass
    
    def main():
        pass
    
    if __name__ == '__main__':
        main()
    		
    #!/usr/bin/python
    '''A brief description of the module.
    
    Extended description.
    
    '''
    
    __author__ = "Lin Chen"
    __license__ = "GPL"
    __version__ = "0.1"
    __email__ = "lchen@ecsu.edu"
    __status__ = "Prototype"
    
    class Car:
        '''Summary line.
    
        Extended description.
    
        Args:
            color (str): color of the car.
            maker (str): maker of the car.
    
        '''
    
        def __init__(self, c, m):
            '''Initialize a car.
    
            Extended description.
    
            Args:
                c (str): color of the car.
                m (str): maker of the car.
    
            '''
            pass
    
        def printCar():
            '''Print the car information.
    
            '''
            pass
    		
    Access docstring
  • help(moduleName)
  • help(moduleName.functionName)
  • print moduleName.__doc__
  • Reference
  • Geeksforgeeks
  • PEP257: Good Python docstrings
  • PEP257 -- Docstring Conventions
  • Google Style Python Docstrings