5 Star 4 Fork 0

Gitee 极速下载 / python-patterns

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/faif/python-patterns
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
chaining_method.py 712 Bytes
一键复制 编辑 原始数据 按行查看 历史
asaffifee 提交于 2023-01-21 22:40 . Update chaining_method.py
from __future__ import annotations
class Person:
def __init__(self, name: str) -> None:
self.name = name
def do_action(self, action: Action) -> Action:
print(self.name, action.name, end=" ")
return action
class Action:
def __init__(self, name: str) -> None:
self.name = name
def amount(self, val: str) -> Action:
print(val, end=" ")
return self
def stop(self) -> None:
print("then stop")
def main():
"""
>>> move = Action('move')
>>> person = Person('Jack')
>>> person.do_action(move).amount('5m').stop()
Jack move 5m then stop
"""
if __name__ == "__main__":
import doctest
doctest.testmod()
Python
1
https://gitee.com/mirrors/python-patterns.git
git@gitee.com:mirrors/python-patterns.git
mirrors
python-patterns
python-patterns
master

搜索帮助