推荐11个实用Python库

yipeiwu_com5年前Python基础

1) delorean

非常酷的日期/时间库

复制代码 代码如下:

from delorean import Delorean
EST = "US/Eastern"
d = Delorean(timezone=EST)

2) prettytable

可以在浏览器或终端构建很不错的输出

复制代码 代码如下:

from prettytable import PrettyTable
table = PrettyTable(["animal", "ferocity"])
table.add_row(["wolverine", 100])
table.add_row(["grizzly", 87])
table.add_row(["Rabbit of Caerbannog", 110])
table.add_row(["cat", -1])
table.add_row(["platypus", 23])
table.add_row(["dolphin", 63])
table.add_row(["albatross", 44])
table.sort_key("ferocity")
table.reversesort = True
+----------------------+----------+
|        animal        | ferocity |
+----------------------+----------+
| Rabbit of Caerbannog |   110    |
|      wolverine       |   100    |
|       grizzly        |    87    |
|       dolphin        |    63    |
|      albatross       |    44    |
|       platypus       |    23    |
|         cat          |    -1    |
+----------------------+----------+

3) snowballstemmer

非常瘦小的语言转换库,支持15种语言

复制代码 代码如下:

from snowballstemmer import EnglishStemmer, SpanishStemmer
EnglishStemmer().stemWord("Gregory")
# Gregori
SpanishStemmer().stemWord("amarillo")
# amarill

4) wget

Python的网络爬虫库

复制代码 代码如下:

import wget
wget.download("
# 100% [............................................................................] 280385 / 280385

5) PyMC

PyMC,一个用于贝叶斯分析的函数库

复制代码 代码如下:

from pymc.examples import disaster_model
from pymc import MCMC
M = MCMC(disaster_model)
M.sample(iter=10000, burn=1000, thin=10)
[-----------------100%-----------------] 10000 of 10000 complete in 1.4 sec

6) sh

将shell命令作为函数导入Python脚本

复制代码 代码如下:

from sh import find
find("/tmp")
/tmp/foo
/tmp/foo/file1.json
/tmp/foo/file2.json
/tmp/foo/file3.json
/tmp/foo/bar/file3.json

7) fuzzywuzzy

用于字符串匹配率、令牌匹配等

复制代码 代码如下:

from fuzzywuzzy import fuzz
fuzz.ratio("Hit me with your best shot", "Hit me with your pet shark")
# 85

8) progressbar

如其名,一个滚动条函数库

复制代码 代码如下:

from progressbar import ProgressBar
import time
pbar = ProgressBar(maxval=10)
for i in range(1, 11):
    pbar.update(i)
    time.sleep(1)
 pbar.finish()
# 60% |########################################################                                      |

9) colorama

一个色彩库,可以为文本添加丰富的色彩

10) uuid

一个可以产生唯一uuid的库

复制代码 代码如下:

import uuid
print uuid.uuid4()
# e7bafa3d-274e-4b0a-b9cc-d898957b4b61

11) bashplotlib

Python的绘图控件,可以绘制直方图、散点图等

复制代码 代码如下:

$ pip install bashplotlib
$ scatter --file data/texas.txt --pch x

以上就是本文推荐的11个使用的python库了,也许有些你没有见过,但都是些非常棒的pyton库,希望大家能够喜欢。

相关文章

python2.7到3.x迁移指南

目前,Python 科学栈中的所有主要项目都同时支持 Python 3.x 和 Python 2.7,不过,这种情况很快即将结束。去年 11 月,Numpy 团队的一份声明引发了数据科学...

Python Numpy库安装与基本操作示例

Python Numpy库安装与基本操作示例

本文实例讲述了Python Numpy库安装与基本操作。分享给大家供大家参考,具体如下: 概述 NumPy(Numeric Python)扩展包提供了数组功能,以及对数据进行快速处理的函...

python 拷贝特定后缀名文件,并保留原始目录结构的实例

如下所示: #!/usr/bin/python # -*- coding: UTF-8 -*- import os import shutil def cp_tree_ext(ex...

比较详细Python正则表达式操作指南(re使用)

比较详细Python正则表达式操作指南(re使用)

Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式。Python 1.5之前版本则是通过 regex 模块提供 Emecs 风格的模式。Emacs 风格模...

Python如何获取系统iops示例代码

iops简介 iops主要用在数据方面,这个指标是数据库性能评定的一个重要参考,iops的是每秒进行读写(I/O)操作的次数,主要看随机访问的性能,一般为了iops增高都要依靠磁盘阵列,...