10

哪些 Python 库让你相见恨晚?

 3 years ago
source link: http://www.justdopython.com/2020/11/18/xjhw/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

哪些 Python 库让你相见恨晚?可能有些人见过这个问题,其实这就是知乎上的一个提问,问题链接为:https://www.zhihu.com/question/24590883,相见恨晚意思是遗憾相识太晚,也就是哪些 Python 让你遗憾相识太晚?这个问题对每个人及每个人的不同阶段可能都会有所不同,所以大家也不用纠结于别人与自己看法是否相同的问题,本文选取自己之前回答中几个有特点的库向大家介绍一下。

face-mask

face-mask 实现了给照片带口罩以及检测是否戴口罩的功能,使用之前需执行 pip install face-mask 装一下。

举一个我之前实现的示例,因当时在播电视剧《猎狐》,所以就选了猎狐 F4 的照片为原型,原图如下:

实现给照片带口罩,执行命令 face-mask x.PNG --red,效果如下:

检测照片是否带口罩,执行命令 python pytorch_infer.py --img-path C:\Users\admin\Desktop\xx.PNG,效果如下:

通过使用 myqr,我们只需几行 Python 代码即可生成炫酷的动态二维码,使用之前需执行 pip install myqr 装一下,看一下我之前实现的示例,效果如下:

如果不了解具体实现,可以看一下我之前写的这篇:用 Python 生成炫酷二维码及解析

cutecharts

与 Matplotlib 、pyecharts 等常见的图表不同,使用 cutecharts 可以生成手绘风格的各种图表,实现之前需执行 pip install cutecharts 装一下,看一下相应效果:

项目地址为:https://github.com/cutecharts/cutecharts.py,如果感觉兴趣的话,可以去看一下,具体使用里面也有相应介绍,这里不再多说。

you-get

you-get 可以说是一个神器,一行命令即可下载很多网站视频,使用之前需执行 pip install you-get 装一下,当时《后浪》视频刷爆 B 站,所以就以下载《后浪》做了示例,如图所示:

colorama

colorama 可以跨多终端,显示字体不同的颜色和背景,使用之前需执行 pip install colorama 装一下。

举一个我之前实现的示例,效果如下:

实现代码如下:

import time, colorama
from random import randint

colorama.init(convert=True)
RED = colorama.Fore.RED + colorama.Style.BRIGHT
CYAN = colorama.Fore.CYAN + colorama.Style.BRIGHT
GREEN = colorama.Fore.GREEN + colorama.Style.BRIGHT
YELLOW = colorama.Fore.YELLOW + colorama.Style.BRIGHT
MAGENTA = colorama.Fore.MAGENTA + colorama.Style.BRIGHT

# 打印抬头
for i in range(1, 35):
    print('')
# *的位置
heartStars = [2, 4, 8, 10, 14, 20, 26, 28, 40, 44, 52, 60, 64, 76]
# 空格的位置
heartBreakLines = [13, 27, 41, 55, 69, 77]
# 玫瑰的空列位置
flowerBreakLines = [7, 15, 23, 31, 39, 46]

# 添加空列
def addSpaces(a):
    count = a
    while count > 0:
        print(' ', end='')
        count -= 1

# 添加空行
def newLineWithSleep():
    time.sleep(0.3)
    print('\n', end='')

play = 0
while play == 0:
    Left_Spaces = randint(8, 80)
    addSpaces(Left_Spaces)
    # 画心
    for i in range(0, 78):
        if i in heartBreakLines:
            newLineWithSleep()
            addSpaces(Left_Spaces)
        elif i in heartStars:
            print(RED + '*', end='')
        elif i in (32, 36):
            print(GREEN + 'M', end='')
        elif i == 34:
            print(GREEN + 'O', end='')
        else:
            print(' ', end='')
    newLineWithSleep()
    addSpaces(randint(8, 80))
    print(CYAN + '祝天下母亲节日快乐!', end='')
    newLineWithSleep()
    newLineWithSleep()
    Left_Spaces = randint(8, 80)
    addSpaces(Left_Spaces)
    # 画花
    for i in range(0, 47):
        if i in flowerBreakLines:
            newLineWithSleep()
            addSpaces(Left_Spaces)
        elif i in (2, 8, 12, 18):
            print(MAGENTA + '{', end='')
        elif i in (3, 9, 13, 19):
            print(MAGENTA + '_', end='')
        elif i in (4, 10, 14, 20):
            print(MAGENTA + '}', end='')
        elif i in (27, 35, 43):
            print(GREEN + '|', end='')
        elif i in (34, 44):
            print(GREEN + '~', end='')
        elif i == 11:
            print(YELLOW + 'o', end='')
        else:
            print(' ', end='')
    print('\n', end='')

本文选取了自己之前回答中个人认为有一些特点的库,大家如果对这个问题感兴趣的话,可以到问题下面看看其他回答,看看能不能发现让自己相见恨晚的 Python 库。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK