quotes = ('A man is not complete until he is married. Then he is finished.',
'As I said before, I never repeat myself.',
'Behind a successful man is an exhausted woman.',
'Black holes really suck...', 'Facts are stubborn things.') class QuoteModel: def get_quote(self, n):
try:
value = quotes[n]
except IndexError as err:
value = 'Not found!'
return value class QuoteTerminalView: def show(self, quote):
print('And the quote is: "{}"'.format(quote)) def error(self, msg):
print('Error: {}'.format(msg)) def select_quote(self):
return input('Which quote number would you like to see?') class QuoteTerminalController: def __init__(self):
self.model = QuoteModel()
self.view = QuoteTerminalView() def run(self):
valid_input = False
while not valid_input:
n = self.view.select_quote()
try:
n = int(n)
except ValueError as err:
self.view.error("Incorrect index '{}'".format(n))
else:
valid_input = True
quote = self.model.get_quote(n)
self.view.show(quote) def main():
controller = QuoteTerminalController()
while True:
controller.run() if __name__ == '__main__':
main()

  

MVC模式:python案例的更多相关文章

  1. MVC模式入门案例

    import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widg ...

  2. python的设计模式之MVC模式

    模型-视图-控制器模式 关注点分离(Separation of Concerns,SoC)原则是软件工程相关的设计原则之一.SoC原则背后的思想是将一个应用切分成不同的部分,每个部分解决一个单独的关注 ...

  3. Python设计模式之MVC模式

    # -*- coding: utf-8 -*- # author:baoshan quotes = ('A man is not complete until he is married. Then ...

  4. 【案例分享】使用ActiveReports报表工具,在.NET MVC模式下动态创建报表

    提起报表,大家会觉得即熟悉又陌生,好像常常在工作中使用,又似乎无法准确描述报表.今天我们来一起了解一下什么是报表,报表的结构.构成元素,以及为什么需要报表. 什么是报表 简单的说:报表就是通过表格.图 ...

  5. python 设计模式之MVC模式

    一.简单介绍 mvc模式  the  model-view-controller pattern mvc模式是一个运用在软件工程中的设计模式.mvc模式脱离了以前简单的web服务设计逻辑,将开发,测试 ...

  6. Django的MVT模式与MVC模式

    Django的MVT模式与MVC模式 在正式开始coding之前,我觉得有必要探讨下Django的MVT模式,理论和实践相结合,才能更好的掌握一门技术.Django中的MVT模式,Django就是属于 ...

  7. MVC模式-----struts2框架(2)

    MVC模式-----struts2框架 第一个struts2程序 struts2框架是通过一个过滤器将struts2集成到Web应用程序中的,这个过滤器的对象是StrutsprepareAndExec ...

  8. Extjs MVC模式开发,循序渐进(一)

    本文讲述extjs mvc的Helloworld,tabPanel,event,页面布局layout等内容. 本页包含:MVC模式案例(一)~MVC模式案例(六),从搭建extjs mvc到点击按钮生 ...

  9. 网页的MVC模式简介

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- #MVC:Model-View-Controller 模型-视图-控制器 #Python处理URL的函数就 ...

  10. [转载]WIKI MVC模式

    MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controller). MVC模式最 ...

随机推荐

  1. Bash 脚本 getopts为什么最后一个參数取不到

    看以下的Bash脚本: #!/bin/bash interval=0 count=0 pid="" while getopts "p:d:n" arg do c ...

  2. 浅谈session测试

    Session 是用于保持状态的基于 Web 服务器的方法,在 Web 服务器上保持用户的状态信息供在任何时间从任何页访问.Session 允许通过将对象存储在 Web 服务器的内存中在整个用户会话过 ...

  3. UGUI 的多分辨率适配

    1.Canvas的属性配置 2.Canvas Scaler的属性配置 3.根据不同的屏幕的比例动态修改缩放基准 void Start () { float standard_width = 960f; ...

  4. AOPR密码过滤器

    在Advanced Office Password Recovery任一攻击的破解选项设置窗口都有一个“编辑密码过滤器”按钮,设置好AOPR密码破解工具的密码过滤器可以大大提高破解速度,下文将具体介绍 ...

  5. GIS-ArcGIS 数据库备份还原

    Create directory sdebak as 'E:\10_DataFile'; alter system set deferred_segment_creation=false; ALTER ...

  6. linux系统socket通信编程2

    一.概述 TCP(传输控制协议)和UDP(用户数据报协议是网络体系结构TCP/IP模型中传输层一层中的两个不同的通信协议. TCP:传输控制协议,一种面向连接的协议,给用户进程提供可靠的全双工的字节流 ...

  7. UITextView和UITextField的placeholder,键盘隐藏,键盘换行变完成字样

    本文转载至 http://blog.csdn.net/hengshujiyi/article/details/9086093- (void)initFeedBackViews { //设置页面的背景颜 ...

  8. Map的有序实现类和无序实现类

    1.HashMap不是有序的: 2.TreeMap和LinkedHashMap是有序的(TreeMap默认升序,LinkedHashMap则记录了插入顺序).

  9. Hacking up an armv7s library

    NOTE: Please take care with this. I obviously cannot test if this will actually work on a new iPhone ...

  10. Uni2D —— 入门(全)

    Uni2D 入门 Uni2D 入门 -- Atlas Uni2D 入门 -- Animation Clip 和 Animation API Uni2D 入门 -- Skeletal Animation ...