Skip to content

Instantly share code, notes, and snippets.

@fmartingr
Last active November 19, 2022 10:47
Show Gist options
  • Save fmartingr/4072832 to your computer and use it in GitHub Desktop.
Save fmartingr/4072832 to your computer and use it in GitHub Desktop.
Custom print function in python with colors.
from sys import stdout
class Colors:
HEADER = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
END = '\033[0m'
def echo(string, end='\r\n', color=None):
if color:
stdout.write("%s%s%s" % (
color,
string,
Colors.END
))
else:
stdout.write(string)
if end:
stdout.write("\n")
echo('Dis is demo text')
echo('Dis is demo text', color=Colors.BLUE)
echo('=> ', color=Colors.RED, end='')
echo('MEH', color=Colors.GREEN)
echo('Dis is demo text', color=Colors.HEADER, end='')
echo('Dis is demo text', color=Colors.BLUE)
@Dalab21
Copy link

Dalab21 commented Nov 19, 2022

allo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment