Last active
October 26, 2017 15:47
-
-
Save rezemika/083a48a3d217432cb6fb3c2457f36139 to your computer and use it in GitHub Desktop.
Some useful expressions in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This gist contains some useful things which are frequently used in Python or are boring to copy by hand. | |
Index: | |
- L11-L45 : ANSI characters to color and format outputs to Linux terminals. | |
- L47-L100 : Weekdays and months names. | |
Feel free to post any idea or suggestion! | |
""" | |
# An Enum with all ANSI characters allowing to color / modify text in a Linux console. | |
# See https://misc.flogisoft.com/bash/tip_colors_and_formatting | |
class Color(Enum): | |
"""ANSI characters to color printed strings. (Foreground, Background)""" | |
NONE = ('', '') | |
RESET = ("\033[39m", "\033[49m") | |
BLACK = ("\033[30m", "\033[40m") | |
RED = ("\033[31m", "\033[41m") | |
GREEN = ("\033[32m", "\033[42m") | |
YELLOW = ("\033[33m", "\033[43m") | |
BLUE = ("\033[34m", "\033[44m") | |
MAGENTA = ("\033[35m", "\033[45m") | |
CYAN = ("\033[36m", "\033[46m") | |
LIGHT_GRAY = ("\033[37m", "\033[47m") | |
DARK_GRAY = ("\033[90m", "\033[100m") | |
LIGHT_RED = ("\033[91m", "\033[101m") | |
LIGHT_GREEN = ("\033[92m", "\033[102m") | |
LIGHT_YELLOW = ("\033[93m", "\033[103m") | |
LIGHT_BLUE = ("\033[94m", "\033[104m") | |
LIGHT_MAGENTA = ("\033[95m", "\033[105m") | |
LIGHT_CYAN = ("\033[96m", "\033[106m") | |
WHITE = ("\033[97m", "\033[107m") | |
class Format(Enum): | |
"""ANSI characters to format printed strings. (Foreground, Reset)""" | |
BOLD = ("\033[1m", "\033[21m") | |
DIM = ("\033[2m", "\033[22m") | |
UNDERLINE = ("\033[4m", "\033[24m") | |
BLINK = ("\033[5m", "\033[25m") | |
REVERSE = ("\033[7m", "\033[27m") | |
HIDDEN = ("\033[8m", "\033[28m") | |
RESET_ALL = ("\033[0m", "\033[0m") | |
# Weekdays and months. | |
# Cause it's boring to hand write that. | |
WEEKDAYS = ( | |
"Monday", | |
"Tuesday", | |
"Wednesday", | |
"Thursday", | |
"Friday", | |
"Saturday", | |
"Sunday" | |
) | |
MONTHS = ( | |
"January", | |
"February", | |
"March", | |
"April", | |
"May", | |
"June", | |
"July", | |
"August", | |
"September", | |
"October", | |
"November", | |
"December" | |
) | |
# Same thing ready for translation. | |
WEEKDAYS = ( | |
_("Monday"), | |
_("Tuesday"), | |
_("Wednesday"), | |
_("Thursday"), | |
_("Friday"), | |
_("Saturday"), | |
_("Sunday") | |
) | |
MONTHS = ( | |
_("January"), | |
_("February"), | |
_("March"), | |
_("April"), | |
_("May"), | |
_("June"), | |
_("July"), | |
_("August"), | |
_("September"), | |
_("October"), | |
_("November"), | |
_("December") | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment