class Printer: def __init__(self): self.log = '' def __repr__(self): return self.log def __call__(self, *args, **kwargs): self.log += str(args) + '\n' __builtins__.print(*args, **kwargs) class print(metaclass = type('', (type,), dict(__repr__ = lambda self: print.log))): log = '' def __init__(self, *args, **kwargs): print.log += str(args) + '\n' __builtins__.print(*args, **kwargs) if __name__ == '__main__': print(1, 2, 3) print(4, 5) print(repr(print)) # 1 2 3 # 4 5 # (1, 2, 3) # (4, 5) print = Printer() print(1, 2, 3) print(4, 5) print(repr(print)) # 1 2 3 # 4 5 # (1, 2, 3) # (4, 5)