python utils是一个模块,其中包含一些标准python安装中未包含的方便实用程序

python-utils的Python项目详细描述


https://travis-ci.org/WoLpH/python-utils.svg?branch=masterhttps://coveralls.io/repos/WoLpH/python-utils/badge.svg?branch=master

python utils是小python函数和 使公共模式更短更容易的类。这决不是 完整的收藏,但它在过去对我很有用,我会 继续延伸。

使用python utils的库之一是django utils。

文档位于:https://python-utils.readthedocs.org/en/latest/

安装要求:

  • six any recent version

安装:

软件包可以通过pip安装(这是推荐的方法):

pip install python-utils

或者,如果没有pip,那么也可以使用easy_install:

easy_install python-utils

或者从pypi(https://pypi.python.org/pypi/python-utils)或github下载最新版本。

请注意,pypi上的版本是用我的gpg密钥(https://pgp.mit.edu/pks/lookup?op=vindex&search=0xE81444E9CE1F695D)签名的,可以使用gpg进行检查:

gpg –verify python-utils-<version>.tar.gz.asc python-utils-<version>.tar.gz

快速启动

此模块使在python脚本中执行常见任务变得容易,例如 将文本转换为数字并确保字符串为Unicode或字节 格式。

示例

从几乎每个字符串中提取数字:

frompython_utilsimportconvertersnumber=converters.to_int('spam15eggs')assertnumber==15number=converters.to_int('spam')assertnumber==0number=converters.to_int('spam',default=1)assertnumber==1number=converters.to_float('spam1.234')

要以编程方式执行全局导入,可以使用import\u global 功能。这有效地模拟了来自…import的

frompython_utils.import_importimport_global# The following is  the equivalent of `from some_module import *`import_global('some_module')

或者在您的类中添加一个名为logger的对应项,该日志可以轻松访问:

classMyClass(Logged):def__init__(self):Logged.__init__(self)my_class=MyClass()# Accessing the logging method:my_class.error('error')# With formatting:my_class.error('The logger supports %(formatting)s',formatting='named parameters')# Or to access the actual log function (overwriting the log formatting can# be done n the log method)importloggingmy_class.log(logging.ERROR,'log')

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

推荐PyPI第三方库


热门话题
具有MVC模式的java观察者/可观察对象   java junit在测试执行后未清理记录器   java减少spring boot应用程序中的网络延迟   java MyFirstApp教程Android Studio sendMessage问题   java无法转换消息   java JSP如果是,则递增   URL和方法的java spring安全设置   spring中的java自动动态绑定   java在Wicket中构建表   使用JUnit在与main相同的类中使用java测试方法   使用tomcat 8管理器部署后,java找不到WAR文件路径   java原子整数错误行为   需要java吗?   java允许多个JLabel中的文本重叠   java Hadoop mapreduce映射程序编程   json参数化Jackson Java库的JsonProperty值