首页 电脑 电脑学堂 查看内容

11个你可能不知道的Python库

2015-2-3 11:34 735 0

摘要: 1) delorean非常酷的日期/时间库from delorean import Delorean EST = "US/Eastern" d = Delorean(timezone=EST) ...
关键词: import table prettytable progressbar delorean add row uuid file 一个

1) delorean非常酷的日期/时间库from delorean import Delorean EST = "US/Eastern" d = Delorean(timezone=EST) 2) prettytable 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) wgetPython的网络爬虫库import wget wget.download(" # 100% [............................................................................] 280385 / 280385 5) PyMCPyMC,一个用于贝叶斯分析的函数库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) bashplotlibPython的绘图控件,可以绘制直方图、散点图等$ pip install bashplotlib $ scatter --file data/texas.txt --pch x
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部