Nowadays I pretty much only using the Python Rich implementation for printing. i.e from rich import print
.
Rather than adding this to every script I write, is there a way to replace the built-in Python print with the Rich implementation?
Nowadays I pretty much only using the Python Rich implementation for printing. i.e from rich import print
.
Rather than adding this to every script I write, is there a way to replace the built-in Python print with the Rich implementation?
You can create a script usercustomize.py
inside the user site-packages directory which performs the import and assigns it to the builtins
:
import builtins
import rich
builtins.print = rich.print
Also check the documentation of the site
module for more information (the same can be achieved for all users via sitecustomize.py
).
You could use ~/.pythonrc.py for your local repl.
# ~/.pythonrc.py
from rich import print