mixin,它将“数据类实例”与其他实例之间的转换更加简单。
owlmixin的Python项目详细描述
< H1> OWLMIXIN < /H1>
(__)v5.0有中断更改
TIterator#group_by
- 返回
TDict[TList[T]]
,而不是TDict[TIterator[T]]
- 返回
(__)v4.0有中断更改
OwlMixin
- 必须在
from_XXX
和to_XXX
中使用关键字参数,但某些参数除外 from_csvf
->;from_csvf_to_list
- 必须在
TList
head
->;take
partial
->;partition
(左右切换)
transformers.XXX
- 必须在中使用关键字参数
to_dict
to_dicts
to_json
to_jsonf
to_yaml
to_yamlf
to_csv
to_csvf
- 必须在中使用关键字参数
动机
你有没有想过用python编写健壮的代码?这个图书馆将使你的愿望成真。
定义扩展OwlMixin的数据类,可以使用一些有用的方法来帮助代码健壮。
请参阅以下Example
和API Reference
部分。
安装
$ pip install owlmixin
API参考
https://tadashi-aikawa.github.io/owlmixin/
示例
fromowlmixinimportOwlMixin,OwlEnum,TOption,TListclassColor(OwlEnum):RED="red"GREEN="green"BLUE="blue"classFood(OwlMixin):id:intname:strcolor:TOption[Color]classHuman(OwlMixin):id:intname:strfavorite:TList[Food]jiro=Human.from_dict({"id":10,"name":"jiro","favorite":[{"id":1,"name":"apple"},{"id":2,"name":"orange","color":"green"}]})
然后…
>>> jiro.id
10
>>> jiro.name
'jiro'
>>> print(jiro.to_dict())
{'id': 10, 'name': 'jiro', 'favorite': [{'id': 1, 'name': 'apple'}, {'id': 2, 'name': 'orange', 'color': 'green'}]}
>>> print(jiro.favorite[0].to_pretty_json())
{
"id": 1,
"name": "apple"
}
>>> print(jiro.to_yaml())
favorite:
- id: 1
name: apple
- color: green
id: 2
name: orange
id: 10
name: jiro
>>> print(jiro.favorite.to_csv(['id', 'name', 'color'], with_header=True))
id,name,color
1,apple,
2,orange,green
您还可以使用方法链,如下所示。
Below sample code uses kachayev/fn.py, great package!!
fromowlmixinimportOwlMixin,TOption,TIteratorfromfnimport_classRepository(OwlMixin):id:intname:strdescription:TOption[str]stargazers_count:intclassGithubRepository(OwlMixin):total_count:intincomplete_results:boolitems:TIterator[Repository]
然后…
>>>print(...GithubRepository....from_json_url("https://api.github.com/search/repositories?q=git")....items....filter(_.stargazers_count>100)....order_by(_.stargazers_count,True)....take(5)....emap(lambdav,i:{...'RANK':i+1,...'STAR':v.stargazers_count,...'NAME':v.name,...'DESCRIPTION':v.description...})....to_csv(fieldnames=["RANK","STAR","NAME","DESCRIPTION"],with_header=True)...)RANK,STAR,NAME,DESCRIPTION1,84643,gitignore,Acollectionofuseful.gitignoretemplates2,30456,gogs,Gogsisapainlessself-hostedGitservice.3,29908,git-flight-rules,Flightrulesforgit4,27704,git,GitSourceCodeMirror-Thisisapublish-onlyrepositoryandallpullrequestsareignored.PleasefollowDocumentation/SubmittingPatchesprocedureforanyofyourimprovements.5,15541,tips,Mostcommonlyusedgittipsandtricks.
你不觉得聪明吗?
对于开发者
需要pipenv和make。
命令
# Create env
$ make init
# Build documentation and run server locally
$ make serve-docs
版本升级
windows不受支持!!!
在发布之前,您需要
- 确认您的分行名称等于发行版本
然后
$ make release