pelper-python助手函数

pelper的Python项目详细描述


read the docsCoverage statusBuild statusPyPI pageGithub page

pelper–python helper函数可以简化测量、忽略、缓存, python 2.7、3.4和3.5的管道、功能帮助程序等。

pelper包含有用的助手函数、装饰器、上下文管理器 -所有能让你的python生活简单一点的事情。 pelper没有依赖项, 覆盖率100%, 而且有很好的记录。

示例

管道数据通过UNIX类/类药剂管:

>>>frompelperimportpipe>>>pipe("some datat, some data",set,(sorted,{"reverse":True}))['t','s','o','m','e','d','a',',',' ']

pelper提供p-函数,即第一个参数是数据的函数。 有pmap(与map类似,但与pipel一起工作):

>>>frompelperimportpipe,pmap>>>pipe(...range(5),...(pmap,lambdax:x*x),...list)[0,1,4,9,16]

…还有过滤器:

>>>frompelperimportpipe,pfilter>>>pipe(...range(5),...(pfilter,lambdax:x>2),...list)[3,4]

从iterables中获取n元素(如果不能使用方括号,则很有用 符号,例如,如果您使用管道)

>>>frompelperimporttake>>>take("hello world",5)['h','e','l','l','o']

从iterables中获取第n个元素(如果您不能使用正方形 括号符号,例如,如果您使用管道)

>>>frompelperimportnth>>>nth(range(5),2)2

展平任意嵌套的列表:

>>>frompelperimportflatten>>>flatten([1,[2,2,[3,3]]])[1,2,2,3,3]

测量功能的持续时间:

>>>frompelperimportprint_duration>>>@print_duration()...deff(n):pass

测量上下文的持续时间:

>>>frompelperimportprint_duration>>>withprint_duration():...range(4)

忽略例外:

>>>frompelperimportignored>>>withignored(OSError):...raiseOSError()# this is ignored

缓存已计算的函数结果:

>>>frompelperimportcache>>>@cache>>>deffib(n):...return1ifn<2elsefib(n-1)+fib(n-2)>>>f(500)# this would run for quite a wile without the cache decorator

更容易打印和格式化:

>>>frompelperimportprintf>>>printf("Hello {name}, I'm {something}",name="Alan",something="world")HelloAlan,I'm world

安装

pelper只是一个文件,没有依赖项。 您只需将pelper.py放入您的项目并使用它。

或者通过运行:

pip install pelper

或者通过运行以下命令从源代码安装:

pip install .

开发

使用virtualenv处理pelper。 通过:

pip install -e requirements-dev.txt

测试

pelper使用doctest、py.testtox进行测试。 它还有Coverage status覆盖范围。

您可以对所有受支持的python版本运行测试,并构建和测试 文档:

tox

仅对指定版本的python运行测试:

tox -e py27,py34,py35

或者只对当前版本的python运行测试:

py.test

文件

通过以下途径生成文档:

cd docs
sphinx html

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
junit有没有办法在Java中重新初始化静态类?   在浏览器中点击应用程序时java Play框架挂起   文件Java错误中的NullPointerException   使用Java中的SNMP查找网络中计算机的登录名   java包装服务器引导程序已弃用,有什么替代方案?   当客户在等待理发时,java信号量值是否存在问题?   java如何使用JavaMail仅下载特定类型的附件   如何在java中将十进制转换为十六进制   java Slick2D粒子系统不会生成粒子   java检测更改事件来自何处   将Java集合类型参数类设置为数组   java如何从eclipse导出为可运行JAR文件?   java EntityManager对象未注入Glassfish和Spring   swing从actionPerformed和actionListener Java返回字符串   java在给定另一个等价键对象的情况下获取映射项的当前键   无论输入如何,java网络都会产生相同的输出