1

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
  • 107,083
  • 22
  • 201
  • 376
felix001
  • 13,941
  • 29
  • 86
  • 111

2 Answers2

2

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
  • 30,279
  • 8
  • 49
  • 99
0

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

# ~/.pythonrc.py
from rich import print
con--
  • 1,475
  • 1
  • 19
  • 29