Recently shared at work was this TIL from Samuel, Custom alias for pretty printing in Python debugger with .pdbrc (including Django models!).
Here’s my ever so slightly adapted version which also includes printing a reminder to me that these exist.
alias rp import rich; rich.print(%*)
alias rpo import rich; from django import forms; rich.print(forms.model_to_dict(%*))
print("Aliases: Use `rp obj` and `rpo instance` to print objects and model instances.\n")
I already had something similar in my IPython startup script using pprint but I’ve now adapted it to use Rich too.
from django import forms
import rich
rp = rich.print
def rpo(*args):
for instance in args:
rich.print(forms.model_to_dict(instance))
print("Helpers: Use `rp(*args)` and `rpo(*args)` to print objects and model instances.\n")
Thanks for sharing, Samuel.