Borax - python3工具集合库




概述 (Overview)
Borax 是一个Python3工具集合库。包括了以下几个话题:
话题(Topics)
内容
Borax.Calendars
1900-2100年的中国农历日期库
Borax.Choices
声明式的选项类。适用于Django.models.choices 定义。
Borax.Datasets
记录型数据操作库,包括连结(Join)、列选择(fetch)等
Borax.DataStuctures
树形结构,json数据
Borax.Numbers
数字库。包括中文数字、百分数等。
Borax.Patterns
设计模式。包括单例模式、代理对象、延迟对象。
安装 (Installation)
Borax 要求 Python3.5+ 。
可以通过以下两种方式安装 :
使用 pip :
$pip installborax
$poetry add borax
使用示例 (Usage)
Borax.LunarDate: 中国农历日期
一个支持1900-2100年的农历日期工具库。
创建日期,日期推算
from borax.calendars import LunarDate
# 获取今天的农历日期(农历2018年七月初一)
print(LunarDate.today()) # LunarDate(2018, 7, 1, 0)
# 将公历日期转化为农历日期
ld = LunarDate.from_solar_date(2018, 8, 11)
print(ld) # LunarDate(2018, 7, 1, 0)
# 日期推算,返回10天后的农历日期
print(ld.after(10)) # LunarDate(2018, 7, 11, 0)
格式化字符串
today = LunarDate.today()
print(today.strftime('%Y年%L%M月%D')) # '二〇一八年六月廿六'
print(today.strftime('今天的干支表示法为:%G')) # '今天的干支表示法为:戊戌年庚申月辛未日'
Borax.Festival: 国内外节日
分别计算距离 “春节”、“除夕(农历十二月的最后一天)” 还有多少天
from borax.calendars.festivals import get_festival, LunarSchema, DayLunarSchema
festival = get_festival('春节')
print(festival.countdown()) # 7
dls = DayLunarSchema(month=12, day=1, reverse=1)

print(dls.countdown()) # 344
Borax.Numbers: 中文数字处理
不同形式的中文数字
from borax.numbers import ChineseNumbers
# 小写、计量
print(ChineseNumbers.to_chinese_number(204)) # '二百零四'
# 小写、编号
print(ChineseNumbers.order_number(204)) # '二百〇四'
# 大写、计量
print(ChineseNumbers.to_chinese_number(204, upper=True)) # '贰佰零肆'
# 大写、编号
print(ChineseNumbers.to_chinese_number(204, upper=True, order=True)) # '贰佰〇肆'
财务金额
from borax.numbers import FinanceNumbers
print(FinanceNumbers.to_capital_str()) # '壹亿元整'
print(FinanceNumbers.to_capital_str(.23)) # '肆佰伍拾柒万捌仟肆佰肆拾贰元贰角叁分'
print(FinanceNumbers.to_capital_str(.53)) # '壹拾万柒仟元伍角叁分'
Borax.Datasets: 数据列选择
从数据序列中选择一个或多个字段的数据。
from borax.datasets.fetch import fetch
objects = [
{'id': 282, 'name': 'Alice', 'age': 30},
{'id': 217, 'name': 'Bob', 'age': 56},
{'id': 328, 'name': 'Charlie', 'age': 56},
]
names = fetch(objects, 'name')
print(names) # ['Alice', 'Bob', 'Charlie']
文档 (Document)
开发特性和规范 (Development Features)
开源协议 (License)
The MIT License (MIT)
Copyright (c) 2015-2021 kinegratii
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
捐赠 (Donate)
如果你觉得这个项目帮助到了你,你可以帮作者们买一杯咖啡表示感谢!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/54747.html