Decorating Python's builtin print() function

后端 未结 4 659
夕颜
夕颜 2021-01-18 05:36

As we know in Python 3 print() is a function, is it possible to create a decorated version of it wrapped under json.dumps(indent=4)

for ex.

4条回答
  •  旧巷少年郎
    2021-01-18 05:43

    No, it's not possible since print is a builtin function and it's not even a builtin C-level class. This answer provides a way to subclass a builtin object like a str and apply a decorator to one of it's methods.

提交回复
热议问题