2014年5月12日月曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅵ.(Classes and OOP)、CHAPTER 32(Advanced Class Topics)、Test Your Knowledge: Part VI Exercises 9.(he Dead Parrot Sketch)を解いてみる。

その他参考書籍

9.(he Dead Parrot Sketch)

コード(BBEdit)

parrot.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

class Scene:
    def __init__(self):
        self.customer = Customer()
        self.clerk = Clerk()
        self.parrot = Parrot()
    def action(self):
        for cast in [self.customer, self.clerk, self.parrot]:
            cast.line()
        
class Cast:
    def line(self):
        raise Exception('not implemented')
        
class Customer(Cast):
    def line(self):
        print('customer: "that\'s one ex-bird!"')

class Clerk(Cast):
    def line(self):
        print('clerk: "no it isn\'t..."')

class Parrot(Cast):
    def line(self):
        print('parrot: None')

if __name__ == '__main__':
    Scene().action()

入出力結果(Terminal)

$ ./parrot.py
customer: "that's one ex-bird!"
clerk: "no it isn't..."
parrot: None
$

0 コメント:

コメントを投稿

Comments on Google+: