一组有用的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 code在GitHub上可用。请随意:
- Create an issue请求 功能或报告错误。
- Fork the repository然后 下一版本对master分支的更改。
- 发送一个请求并纠缠维护者直到它被合并。确保 添加到AUTHORS并更新 CHANGES。