为了使
python
的输出更有趣味性, 也是增加一些编程的乐趣, 因此我们今天尝试做一些趣味的结果打印. 主要基于两个库:emoji
和colorama
安装
# https://github.com/carpedm20/emoji or https://anaconda.org/conda-forge/emoji
## conda install -c conda-forge emoji
pip install emoji --upgrade
示例:
>> import emoji
>> print(emoji.emojize('Python is :thumbs_up:'))
Python is
>> print(emoji.emojize('Python is :thumbsup:', language='alias'))
Python is
>> print(emoji.demojize('Python is '))
Python is :thumbs_up:
>>> print(emoji.emojize("Python is fun :red_heart:"))
Python is fun ❤
>>> print(emoji.emojize("Python is fun :red_heart:", variant="emoji_type"))
Python is fun ❤️ #red heart, not black heart
>>> print(emoji.is_emoji(""))
True
安装
# https://github.com/tartley/colorama or
## conda install -c anaconda colorama
pip install colorama
示例:
from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')
Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Style: DIM, NORMAL, BRIGHT, RESET_ALL
@online{tartley2022Apr,
author = {tartley},
title = {{colorama}},
organization = {GitHub},
year = {2022},
month = apr,
date = {2022-04-17},
urldate = {2022-04-17},
language = {english},
hyphenation = {english},
note = {[Online; accessed 17. Apr. 2022]},
url = {https://github.com/tartley/colorama},
abstract = {{Simple cross-platform colored terminal text in Python - tartley/colorama: Simple cross-platform colored terminal text in Python}}
}
@online{carpedm202022Apr,
author = {carpedm20},
title = {{emoji}},
organization = {GitHub},
year = {2022},
month = apr,
date = {2022-04-17},
urldate = {2022-04-17},
language = {english},
hyphenation = {english},
note = {[Online; accessed 17. Apr. 2022]},
url = {https://github.com/carpedm20/emoji},
abstract = {{emoji terminal output for Python. Contribute to carpedm20/emoji development by creating an account on GitHub.}}
}