Recently, there was a tweet by Ned Batchelder that illustrated how to make Python REPL output prettier. I went to implement it, and wanted to put together some instructions for the future.
The PYTHONSTARTUP referenced here is an environment variable that points to a python file that we can place a series of command into that will be evaluated when we launch a Python REPL. I have the following code in a file called
The code above will set the
>>> to a light blue and the
... to a darker blue, but this isn’t the part you are here for probably. You want the next line, which sets the displayhook for output to pretty print.
Next, you can export the PYTHONSTARTUP environment variable pointing to your file as shown here.
You can also add this to your
.zshrc depending on which shell you are using, and it will always make your python repl output be pretty.
So what is the difference?
First let’s look at the normal output:
Now let’s see it with the pretty print in place:
If your are curious what the colors look like: