argparse - 命令行选项、参数和子命令解析器

  1. import argparse
  2. parser = argparse.ArgumentParser()
  3. parser.add_argument("echo", help="echo the string you use here")
  4. args = parser.parse_args()
  5. print(args.echo)

然后我们得到:

  1. $ python3 prog.py -h
  2. usage: prog.py [-h] echo
  3. positional arguments:
  4. echo echo the string you use here
  5. optional arguments:
  6. -h, --help show this help message and exit

colorama - 彩色输出

  1. from colorama import Fore, Back, Style
  2. print(Fore.RED + 'some red text')
  3. print(Back.GREEN + 'and with a green background')
  4. print(Style.DIM + 'and in dim text')
  5. print(Style.RESET_ALL)
  6. print('back to normal now')

Clor - 彩色输出

  1. from colr import color
  2. # Examples:
  3. print(color('Hello world.', fore='red', style='bright'))
  4. # Examples (256 Colors):
  5. print(color('Hello world', fore=125, back=80))
  6. # Examples (True Color):
  7. print(color('Hello there.', fore=(255, 0, 0), back=(0, 0, 0)))
  8. # Examples (Hex):
  9. print(color('Hello there.', fore='ff0000', back='000'))

python-cfonts - 高级彩色输出

  1. from cfonts import render, say
  2. output = render('Hello world', colors=['red', 'yellow'], align='center')
  3. print(output)
  4. # 输出
  5. ██╗ ██╗ ███████╗ ██╗ ██╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██╗ ██████╗
  6. ██║ ██║ ██╔════╝ ██║ ██║ ██╔═══██╗ ██║ ██║ ██╔═══██╗ ██╔══██╗ ██║ ██╔══██╗
  7. ███████║ █████╗ ██║ ██║ ██║ ██║ ██║ █╗ ██║ ██║ ██║ ██████╔╝ ██║ ██║ ██║
  8. ██╔══██║ ██╔══╝ ██║ ██║ ██║ ██║ ██║███╗██║ ██║ ██║ ██╔══██╗ ██║ ██║ ██║
  9. ██║ ██║ ███████╗ ███████╗ ███████╗ ╚██████╔╝ ╚███╔███╔╝ ╚██████╔╝ ██║ ██║ ███████╗ ██████╔╝
  10. ╚═╝ ╚═╝ ╚══════╝ ╚══════╝ ╚══════╝ ╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝

progressbar2 - 进度条

  1. import time
  2. import progressbar
  3. for i in progressbar.progressbar(range(100)):
  4. time.sleep(0.02)

fake-useragent - User Agent大全

  1. from fake_useragent import UserAgent
  2. ua = UserAgent()
  3. ua.ie
  4. # Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US);
  5. ua.msie
  6. # Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)'
  7. ua['Internet Explorer']
  8. # Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)
  9. ua.opera
  10. # Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11
  11. ua.chrome
  12. # Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'
  13. ua.google
  14. # Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1290.1 Safari/537.13
  15. ua['google chrome']
  16. # Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
  17. ua.firefox
  18. # Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1
  19. ua.ff
  20. # Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:15.0) Gecko/20100101 Firefox/15.0.1
  21. ua.safari
  22. # Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25
  23. # and the best one, random via real world browser usage statistic
  24. ua.random

pyfiglet - 终端banner

  1. from pyfiglet import Figlet
  2. f = Figlet(font='slant')
  3. print(f.renderText('text to render'))
  4. # 输出:
  5. __ __ __ __
  6. / /____ _ __/ /_ / /_____ ________ ____ ____/ /__ _____
  7. / __/ _ \| |/_/ __/ / __/ __ \ / ___/ _ \/ __ \/ __ / _ \/ ___/
  8. / /_/ __/> </ /_ / /_/ /_/ / / / / __/ / / / /_/ / __/ /
  9. \__/\___/_/|_|\__/ \__/\____/ /_/ \___/_/ /_/\__,_/\___/_/

PrettyTable - 表格输出

  1. from prettytable import PrettyTable
  2. table = PrettyTable(["姓名", "性别", "年龄", "存款"])
  3. table.add_row(["赵一","男", 20, 100000])
  4. table.add_row(["钱二","男", 21, 500])
  5. table.add_row(["孙三", "男", 22, 400.7])
  6. table.add_row(["李四", "男", 23, 619.5])
  7. table.add_row(["周五", "男", 24, 1214.8])
  8. table.add_row(["吴六", "女", 25, 646.9])
  9. table.add_row(["郑七", "女", 26, 869.4])
  10. table.add_row(["王七加一", "男", 21, 869.4])
  11. print(table)
  12. '''
  13. 结果
  14. +----------+------+------+--------+
  15. | 姓名 | 性别 | 年龄 | 存款 |
  16. +----------+------+------+--------+
  17. | 赵一 | 男 | 20 | 100000 |
  18. | 钱二 | 男 | 21 | 500 |
  19. | 孙三 | 男 | 22 | 400.7 |
  20. | 李四 | 男 | 23 | 619.5 |
  21. | 周五 | 男 | 24 | 1214.8 |
  22. | 吴六 | 女 | 25 | 646.9 |
  23. | 郑七 | 女 | 26 | 869.4 |
  24. | 王七加一 | 男 | 21 | 869.4 |
  25. +----------+------+------+--------+
  26. '''

PyInquirer