How to document a method with parameter(s)?

前端 未结 8 1789
情书的邮戳
情书的邮戳 2020-12-07 07:52

How to document methods with parameters using Python\'s documentation strings?

EDIT: PEP 257 gives this example:

d         


        
8条回答
  •  温柔的废话
    2020-12-07 08:12

    Building upon the type-hints answer (https://stackoverflow.com/a/9195565/2418922), which provides a better structured way to document types of parameters, there exist also a structured manner to document both type and descriptions of parameters:

    def copy_net(
        infile: (str, 'The name of the file to send'),
        host: (str, 'The host to send the file to'),
        port: (int, 'The port to connect to')):
    
        pass
    

    example adopted from: https://pypi.org/project/autocommand/

提交回复
热议问题