3

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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
felix001
  • 15,341
  • 32
  • 94
  • 121

2 Answers2

5

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).

a_guest
  • 34,165
  • 12
  • 64
  • 118
0

You could use ~/.pythonrc.py for your local repl.

# ~/.pythonrc.py
from rich import print
ConorSheehan1
  • 1,640
  • 1
  • 18
  • 30