Define functions with too many arguments to abide by PEP8 standard

前端 未结 7 650
日久生厌
日久生厌 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 00:55

    I find myself this way to be quite interesting:

    def my_function(
            argument_one, argument_two, argument_three,
            argument_four, argument_five
    ):
        ...
    

    it allows code-folding to reveal the function signatures quite easily, for instance, consider the below snippet:

    def my_function(
            argument_one, argument_two, argument_three,
            argument_four, argument_five
    ):
        s1 = 1
        s2 = 2
        if s1 + s2:
            s3 = 3
    
    
    def my_other_function(argument_one, argument_two, argument_three):
        s1 = 1
        s2 = 2
        if s1 + s2:
            s3 = 3
    

    This way allows to code-folding the whole file and seeing all functions/signatures at once, ie:

提交回复
热议问题