Define functions with too many arguments to abide by PEP8 standard

前端 未结 7 636
日久生厌
日久生厌 2021-02-01 00:12

I have defined a function with a long list of arguments. The total characters in definition is above 80 and doesn\'t abide by PEP8.

def my_function(argument_one,         


        
相关标签:
7条回答
  • 2021-02-01 01:05

    An example is given in PEP 8:

    class Rectangle(Blob):
    
        def __init__(self, width, height,
                     color='black', emphasis=None, highlight=0):
    

    So that is the official answer. Personally I detest this approach, in which continuation lines have leading whitespace that doesn't correspond to any real indentation level. My approach would be:

    class Rectangle(Blob):
    
        def __init__(
            self, width, height,
            color='black', emphasis=None, highlight=0
        ):
    

    . . . or just let the line run over 80 characters.

    0 讨论(0)
提交回复
热议问题