python function *args and **kwargs with other specified keyword arguments

前端 未结 3 620
别那么骄傲
别那么骄傲 2021-02-07 15:31

I have a Python class with a method which should accept arguments and keyword arguments this way

class plot:
    def __init__(self, x, y):
        self.x = x
            


        
3条回答
  •  走了就别回头了
    2021-02-07 16:19

    Here's a slight tweek to Jure C.'s answer:

    def set_axis(self, *args, **kwargs):
        xlabel = kwargs.pop('xlabel', 'x')
        ylabel = kwargs.pop('ylabel', 'y')
    

    I changed get to pop to remove xlabel and ylabel from kwargs if present. I did this because the rest of the code in the original question contains a loop that is meant to iterate through all kwargs except for xlabel and ylabel.

提交回复
热议问题