python包mdure_borax: Borax 是一个的 Python3 开发工具集合库,涉及到:设计模式,数据结构及其实现,一些简单函数的封装...

Borax - python3工具集合库

borax.svg

borax.svg

borax.svg

badge.svg

coverage.svg

概述 (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(100000000)) # '壹亿元整'

print(FinanceNumbers.to_capital_str(4578442.23)) # '肆佰伍拾柒万捌仟肆佰肆拾贰元贰角叁分'

print(FinanceNumbers.to_capital_str(107000.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)

如果你觉得这个项目帮助到了你,你可以帮作者们买一杯咖啡表示感谢!

ae8c35b97237b90884141d74abbeadb5.png


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部