我想创建一个类,可以创建具有仅在特定条件下打印的打印函数的子类。将函数的所有参数传递给另一个函数
这里的基本上就是我想要做的事:
class ClassWithPrintFunctionAndReallyBadName:
...
def print(self, *args):
if self.condition:
print(*args)
这个工程已经除了事实,有观点认为,必须与默认print
功能明确指出,如end
(例如: print('Hello, world!', end='')
)。我怎样才能让我的新班级的print
函数接受如end=''
这样的参数并将它们传递给默认的print
?
你可以使用'** kwargs' –