资源简介
精通Python设计模式 高清完整.pdf版+源码 下载
代码片段和文件信息
class Frog:
def __init__(self name):
self.name = name
def __str__(self):
return self.name
def interact_with(self obstacle):
print(‘{} the Frog encounters {} and {}!‘.format(self
obstacle obstacle.action()))
class Bug:
def __str__(self):
return ‘a bug‘
def action(self):
return ‘eats it‘
class FrogWorld:
def __init__(self name):
print(self)
self.player_name = name
def __str__(self):
return ‘\n\n\t------ Frog World ———‘
def make_character(self):
return Frog(self.player_name)
def make_obstacle(self):
return Bug()
class Wizard:
def __init__(self name):
self.name = name
def __str__(self):
return self.name
def interact_with(self obstacle):
print(‘{} the Wizard battles against {} and {}!‘.format(self obstacle obstacle.action()))
class Ork:
def __str__(self):
return ‘an evil ork‘
def action(self):
return ‘kills it‘
class WizardWorld:
def __init__(self name):
print(self)
self.player_name = name
def __str__(self):
return ‘\n\n\t------ Wizard World ———‘
def make_character(self):
return Wizard(self.player_name)
def make_obstacle(self):
return Ork()
class GameEnvironment:
def __init__(self factory):
self.hero = factory.make_character()
self.obstacle = factory.make_obstacle()
def play(self):
self.hero.interact_with(self.obstacle)
def validate_age(name):
try:
age = input(‘Welcome {}. How old are you? ‘.format(name))
age = int(age)
except ValueError as err:
print(“Age {} is invalid please try \
again…“.format(age))
return (False age)
return (True age)
def main():
name = input(“Hello. What‘s your name? “)
valid_input = False
while not valid_input:
valid_input age = validate_age(name)
game = FrogWorld if age < 18 else WizardWorld
environment = GameEnvironment(game(name))
environment.play()
if __name__ == ‘__main__‘:
main()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 2209 2016-03-18 18:41 mpdp-code-master\chapter1\abstract_factory.py
....... 2895 2016-03-18 18:41 mpdp-code-master\chapter1\data\donut.json
....... 1464 2016-03-18 18:41 mpdp-code-master\chapter1\data\person.xm
....... 1952 2016-03-18 18:41 mpdp-code-master\chapter1\factory_method.py
....... 121 2016-03-18 18:41 mpdp-code-master\chapter1\id.py
....... 1398 2016-03-18 18:41 mpdp-code-master\chapter10\chain.py
....... 1778 2016-03-18 18:41 mpdp-code-master\chapter11\command.py
....... 1671 2016-03-18 18:41 mpdp-code-master\chapter11\first-class.py
....... 4723 2016-03-18 18:41 mpdp-code-master\chapter12\interpreter.py
....... 1954 2016-03-18 18:41 mpdp-code-master\chapter13\observer.py
....... 2733 2016-03-18 18:41 mpdp-code-master\chapter14\state.py
....... 524 2016-03-18 18:41 mpdp-code-master\chapter15\langs.py
....... 1439 2016-03-18 18:41 mpdp-code-master\chapter15\strategy.py
....... 1925 2016-03-18 18:41 mpdp-code-master\chapter16\graph.py
....... 1689 2016-03-18 18:41 mpdp-code-master\chapter16\graph_template.py
....... 1847 2016-03-18 18:41 mpdp-code-master\chapter16\graph_template_slower.py
....... 570 2016-03-18 18:41 mpdp-code-master\chapter16\template.py
....... 831 2016-03-18 18:41 mpdp-code-master\chapter2\apple-factory.py
....... 4485 2016-03-18 18:41 mpdp-code-master\chapter2\builder.py
....... 871 2016-03-18 18:41 mpdp-code-master\chapter2\builder2.py
....... 1420 2016-03-18 18:41 mpdp-code-master\chapter2\computer-builder.py
....... 396 2016-03-18 18:41 mpdp-code-master\chapter3\clone.py
....... 1829 2016-03-18 18:41 mpdp-code-master\chapter3\prototype.py
....... 775 2016-03-18 18:41 mpdp-code-master\chapter4\adapter.py
....... 414 2016-03-18 18:41 mpdp-code-master\chapter4\external.py
....... 1096 2016-03-18 18:41 mpdp-code-master\chapter5\mymath.py
....... 2600 2016-03-18 18:41 mpdp-code-master\chapter6\facade.py
....... 1789 2016-03-18 18:41 mpdp-code-master\chapter7\flyweight.py
....... 1371 2016-03-18 18:41 mpdp-code-master\chapter8\mvc.py
....... 993 2016-03-18 18:41 mpdp-code-master\chapter9\lazy.py
............此处省略23个文件信息
相关资源
- Django2 文件上传及功能支持中文名文件
- 深度学习入门:基于Python的理论与实
- 《Python3爬虫、数据清洗与可视化》
- IDA.Pro.v7.2_Hgl-Green(Python)+7.0(x86ar
- python项目开发案例集锦
- 《Python开发实战》(PDF版高清扫描版
- opencv_python官方中文教程源码修改版
- Python学习手册(第3版)-带目录完整版
- python2.7:scipy-0.19.0-win64
- Python Cookbook 第3版 中文版.pdf
-
ba
semap-1.2.1-cp37-cp37m-win_amd64.whl - 《Python源码剖析-深度探索动态语言核
- MDNETpython实现
- Python + PyQt5 + MySQL模拟QQ的聊天与娱乐
- 《Python深度学习》2018中文
- opencv3计算机视觉 python实现
- python项目web
- 目标跟踪CSK算法python实现
- Pycharm+Django+Python+MySQL开发
- Python自动化运维技术与最佳实践
- Python学习手册.mobi kindle电子书 带源码
- OpenCV 3-python语言
- Python基础教程 Beginning Python From Novic
- Selenium2 Python自动化测试实战第二版高
- 《selenium2 python 自动化测试实战第二版
- opencv_python-3.4.0+contrib-cp36-cp36m-win_amd
- 机电控制python
- scipy-1.0.0-cp36-none-win_amd64.whl
- python2.7、numpy、matplotlib在windows 64位平
- 《Python深度学习》中文版pdf+英文版
评论
共有 条评论