2 min read

Modified Print Statements

1 Introduction

We often use print statements to get feedback on certain process steps or to present findigs. In this post, I want to show how to use print statements cleverly and make them more descriptive.

2 Loading the libraries and classes

import pandas as pd
import os
class Color:
   PURPLE = '\033[95m'
   CYAN = '\033[96m'
   DARKCYAN = '\033[36m'
   BLUE = '\033[94m'
   GREEN = '\033[92m'
   YELLOW = '\033[93m'
   RED = '\033[91m'
   BOLD = '\033[1m'
   UNDERLINE = '\033[4m'
   END = '\033[0m'

3 Modified Print Statements

3.3 Color Print Statements

To make print statements even more beautiful, we can have parts printed in color or bold. For this we use the Color-class created above.

print('Current Date: ' + Color.RED + today)

print(Color.BLUE + 'Current Date: ' + 
      Color.BOLD + Color.RED + today)

print(Color.RED + 'My ' 
      + Color.END + 
      'Calculation: ' + str(my_calculation))

print(Color.BLUE + 'My ' + Color.END + 
      Color.UNDERLINE + Color.GREEN + 'Calculation:' + Color.END +
      ' ' + Color.BOLD + Color.RED + str(my_calculation))

4 Conclusion

In this short post I showed how to modify Print Statements and have them output in color.