一组有用的python工具!

pockets的Python项目详细描述


让我检查一下我的口袋……

pockets库汇集了我所拥有的许多python助手函数 多年来发现有用。

如果你在一个导出api并访问数据存储的项目上工作过, 您可能看到过这样的代码:

# Receive a data type with underscores from some API
data_type = 'user_preference'

# Convert underscored data type to CamelCase to match the data model
model_name = camel(data_type)

# Resolve the model name into a model class
model_class = resolve(model_name, modules=["webapp.model.admin",
                                           "webapp.model.user",
                                           "webapp.model.businesslogic"]

# Instantiate the model class and do stuff with the instance...
instance = model_class()

当你使用两种不同的框架时,会有阻抗失配; 尤其是当你想更新你的后端,同时保持原有的 与外部api的兼容性。

口袋里装满了经过高度测试、维护良好的功能,有助于桥接 差距。下面是几个例子…

无论您身在何处,都可以轻松找到正确的记录器

>>> from pockets.autolog import log
>>> log.error("Always log from the correct module.Class!")
mymodule.MyClass: Always log from the correct module.Class!

将下划线分隔的字符串转换为camelcase

>>> from pockets import camel
>>> camel("xml_http_request", upper_segments=[1])
'XmlHTTPRequest'

将camelcase字符串转换为下划线

>>> from pockets import uncamel
>>> uncamel("XmlHTTPRequest")
'xml_http_request'

将字符串解析为对象

>>> from pockets import resolve
>>> resolve("calendar.TextCalendar")
<class 'calendar.TextCalendar'>

向前窥视迭代器

>>> from pockets import iterpeek
>>> p = iterpeek(["a", "b", "c", "d", "e"])
>>> p.peek()
'a'
>>> p.next()
'a'
>>> p.peek(3)
['b', 'c', 'd']

下载和文档

完整文档可在Read the Docs上获得。

生成的包在PyPI上可用。

Source codeGitHub上可用。请随意:

生成状态

Build StatusCoverage StatusDocumentation Status

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

推荐PyPI第三方库


热门话题
java将Map<String,String>传递给需要Map<String,Object>   java在循环中使用字符串而不是StringBuilder是否会造成内存损失?   jnlp如何更新java控制台JRE?   java更改、修改和重新打包CXFAPI源文件   JavaFXJava应用程序在Fedora上运行一段时间后关闭   使用来自不同类的方法的java   java如何通过ant脚本在linux中使用subst?   java在使用camunda modeler进行base64编码/解码时出错   获取java。netbeans、weblogic和fastswap设置为true时的lang.NoSuchMethodError   java如何提高FinalizerThread在GC中收集对象的优先级   java检测具有相同根的单词   netbeans crud应用程序中的java错误