#取行数
import linecache
count = linecache.getlines('mv')[1]
print(count)
创业公司喜好的3款Python库
html
Instavest上发表了一篇博文,文章分享了深受创业公司喜好的3款Python库,该文章在Hacker News上引起了开发者的激烈探讨。python
1. Whitenoise(见上面)mysql
2. Phonenumbers(精简版)linux
要识别出电话号码不是件容易的事情,而正则表达式也不必定能处理好各类五花八门的有效电话格式。git
例如:程序员
可见依赖于单一的正则检测不必定能获得想要的答案,因此,要适当借助工具—Phonenumbers。推荐缘由是它小巧,实用简便,没有地理代编码,运营商,时区等metadata数据。它能识别多种格式,而后使用不一样的格式/样式进行有效匹配。github
3. Pdfkitweb
借助Pdfkit能够便捷地把HTML转换成PDF文件。这有何用处呢?比方说你的应用有一个含有发票信息的页面,你就能够透过Pdfkit帮助生成一个PDF文件供用户进行下载,其用法以下:正则表达式
4.Python-dateutilsql
Numerous date utilities for calculating differences, etc. The most useful of these is a resilient date parser:
import dateutil.parser >>> dateutil.parser.parse("May 4th, 2012") datetime.datetime(2012, 5, 4, 0, 0) >>> dateutil.parser.parse("5-4-2012") datetime.datetime(2012, 5, 4, 0, 0) >>> dateutil.parser.parse("5.4.2012") datetime.datetime(2012, 5, 4, 0, 0) >>> dateutil.parser.parse("4th May 2012") datetime.datetime(2012, 5, 4, 0, 0)[Three Useful Python Libraries for Startups]
让人耳目一新的Python库
github: https://github.com/codeinthehole/purl
拥有简洁接口的URL处理器:
>>> from purl import URL >>> from_str = URL('https://www.google.com/search?q=testing') >>> u.query_param('q') u'testing' >>> u.host() u'www.google.com'
github: https://github.com/jaraco/path.py
一个文件系统处理库,不过目前还在开发阶段
from path import path d = path('/home/guido/bin') for f in d.files('*.py'): f.chmod(0755)
https://github.com/coleifer/peewee
小型ORM, 接口很漂亮:
# get tweets by editors ("<<" maps to IN) Tweet.select().where(Tweet.user << editors) # how many active users are there? User.select().where(User.active == True).count()
相似的个人 CURD.py (https://github.com/hit9/CURD.py) :)
User.create(name="John", email="John@gmail.com") # create User.at(2).update(email="John@github.com") # update John = User.where(name="John").select().fetchone() # read # who wrote posts? for post, user in (Post & User).select().fetchall(): print "Author: %s, PostName: %s" % (user.name, post.name)
https://github.com/ponyorm/pony
一个十分独特的ORM,接口简单干净,最大的特色是支持使用generator的语法来进行查询,可使查询语句变得简洁,灵活,并且漂亮。
例如可使用以下的语句来进行一个查询:
select(p for p in Product if p.name.startswith('A') and p.cost <= 1000)
同时,Pony ORM还提供了一个ER图编辑工具来进行数据库原型设计。
https://github.com/halst/schema
一样是docopt的做者编写的,一个数据格式检查库,很是新颖:
>>> from schema import Schema >>> Schema(int).validate(123) 123 >>> Schema(int).validate('123') Traceback (most recent call last): ... SchemaError: '123' should be instance of <type 'int'> Traceback (most recent call last): ... SchemaError: '123' should be instance of <type 'int'>
https://github.com/kachayev/fn.py
加强Python的函数式编程:
from fn import _ print (_ + 2) # "(x1) => (x1 + 2)" print (_ + _ * _) # "(x1, x2, x3) => (x1 + (x2 * x3))"
pocoo出的库,必属精品。 http://www.pocoo.org/
它的库很出名: flask, jinja2, pygments,sphinx
[让人耳目一新的Python库]
Github上Python开发者应该关心的Repo
carbaugh/lice
lice : Generate license files for your projects
一个用来为你的项目生成许可证的工具。这下可方便了,不用手工的去修改了!
peewee: a small, expressive orm – supports postgresql, mysql and sqlite
你在用SQLAlchemy ? 我强烈推荐你看下peewee
来看一个sample:
User.select().where(User.active == True).order_by(User.username)
一个单文件的Python ORM.至关轻巧,支持三个数据库。并且,它最讨人喜欢的是它的轻量级的语法。
autopep8 : A tool that automatically formats Python code to conform to the PEP 8 style guide.
每一个Python程序员都应该checkout的repo.自动的把你的Python代码转成符合PEP8风格的代码.
使用 -i 参数来直接修改你的 Python文件:
autopep8 -i mycode.py
fn.py : Functional programming in Python: implementation of missing features to enjoy FP
这是个颇有趣的项目,来弥补Python在函数式编程方面没有的一些特性。来看个sample:
from fn import _ assert list(map(_ * 2, range(5))) == [0,2,4,6,8]
python-patterns : A collection of design patterns implemented (by other people) in python
这个repo收集了不少设计模式的python写法
six : Six is a Python 2 and 3 compatibility library
Six没有托管在Github上,而是托管在了Bitbucket上,不过这些都不是重点,重点是它的做用。
众所周知 Python 2 和 Python 3 版本的分裂给 Python 开发者们带来了很大的烦恼,为了使代码同时兼容两个版本,每每要增长大量的代码。 因而 Six 出现了。正如它的介绍所说,它是一个专门用来兼容 Python 2 和 Python 3 的库。它解决了诸如 urllib 的部分方法不兼容, str 和 bytes 类型不兼容等“知名”问题。
它的效果怎么样?pypi上单日十万以上,单月几百万的下载量足以说明了。要知道诸如 Flask 和 Django 这类知名的库,月下载量也只有几十万。
[Github上Python开发者应该关心的Repo]
你可能没听过的11个Python库
2) prettytable
你可能从未听过该库,由于它托管在GoogleCode。prettytable主要用于在终端或浏览器端构建很好的输出。
3.snowballstemmer
好吧,我也是首次安装该库。这是一款很是瘦小的语言转换库,支持15种语言。
4.wget
你是否还记得,每一次都会由于某个目的而编写网络爬虫工具,之后不再用了,由于wget就足够你使用了。wget是Python版的网络爬虫库,简单好用。
5.PyMC
scikit-learn彷佛是全部人的宠儿,但在我看来,PyMC更有魅力。PyMC主要用来作Bayesian分析。
7.fuzzywuzzy
Fuzzywuzzy是一个能够对字符串进行模糊匹配的库,你们有空能够去 查看源码。
progressbar是一个进度条库,该库提供了一个文本模式的progressbar。
9.colorama
colorama主要用来给文本添加各类颜色,而且很是简单易用。
bashplotlib是一个绘图库,它容许你使用stdin绘制柱状图和散点图等。
[英文原文: 11 Python Libraries You Might Not Know]