Pass all arguments of a function to another function

前端 未结 5 1533
感动是毒
感动是毒 2021-01-04 06:37

I want to have a class that I can create subclasses of that has a print function that only prints on a particular condition.

Here\'s basically what I\'m trying to do

5条回答
  •  时光说笑
    2021-01-04 07:02

    Just duplicate the named arguments for the method signature.

    def print(self, *args, end='\n', sep=' ', flush=False, file=None):
        if self.condition:
            print(*args, end=end, sep=sep, flush=flush, file=file)
    

提交回复
热议问题