python趣味输出/彩色/emoji
为了使 python 的输出更有趣味性, 也是增加一些编程的乐趣, 因此我们今天尝试做一些趣味的结果打印. 主要基于两个库: emoji 和 colorama
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 ??
>>> print(emoji.is_emoji("👍"))
True
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
reference
@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.}} }
|