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. swift - UIToolbar 的用法

    代码如下: 1.声明及初始化 var toolsBar = UIToolbar() toolsBar.frame = CGRect(x:, y:, width:SCREEN_WIDTH, height ...

  2. 通过ArcGIS Desktop数据发布ArcGIS Server

    1.双击GIS Servers--->Add ArcGIS Server 2.选择Publish GIS Services 3.输入Server URL:http://localhost:608 ...

  3. 关于“ORA-01747: user.table.column, table.column 或列说明无效”的报错。

    今天在工程中遇到“ORA-01747: user.table.column, table.column 或列说明无效”的报错情况,查了一下是由于数据库列名起的不好引起的,名字用到了数据库的关键字.

  4. Java三方---->excel框架之POI的使用一

    Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能.pdf框架之IText的使用,参见我的博客:Java ...

  5. linux 下 git gem 等代理设置问题

    github.com,作为程序员的代码仓库,我们经常会用到.但有时候我们不能直接通过网络链接它,只能通过代理. 这里我有一台代理服务器,起初我以为在终端设置了代理环境就行了,其设置为在你的~/.bas ...

  6. JS:“分享到”之类的悬浮框的运动原理(代码)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. LeetCode——Peeking Iterator

    Description: Given an Iterator class interface with methods: next() and hasNext(), design and implem ...

  8. axios请求本地json

    在vux的项目中 1,首先,json文件的位置: 原因: 访问服务器文件,应该把 json文件放在最外层的static文件夹,这个文件夹是vue-cli内置服务器向外暴露的静态文件夹   2,一定要用 ...

  9. LINUX IPTABLES 防火墙配置

     0.iptables(ACL)的匹配原则: 与cisco等一致,从上到下依次匹配. 1.iptables的基本用法:. (1)命令格式 iptables [–ttable] command [mat ...

  10. 手动把第三方的jar包添加到本地mavne仓库的方法

    在实际实用maven进行开发的过程中,有一些项目没有使用maven来进行打包(比如我在做中文分词时候用的IK分词器),我们就无法在maven的仓库中下载这些jar包,但是我们在开发中会用到这些东西,所 ...