As we write them the notes become available by reloading this page in real time. Designing a multi-screen application (a finite state machine). -bash-3.2$ javac Story.java -bash-3.2$ java Story 20.0 30.0 5.0 -bash-3.2$ cat Story.java class Account { double balance; Account(double balance) { this.balance = balance; } double report() { return this.balance; } void deposit(double amount) { this.balance += amount; } } class Story { public static void main(String[] args) { Account a = new Account(20); System.out.println(a.report()); a.deposit(10); System.out.println(a.report()); a.deposit(-25); System.out.println(a.report()); } } -bash-3.2$ Now let's do the same in Python. class Account(object): def __init__(self, initial): self.balance = initial def deposit(self, amount): self.balance += amount def report(self): return self.balance def main(): a = Account(10) print a.report() a.deposit(20) print a.report() a.deposit(-5) print a.report() Now let's use this for CGI. I will make screens into independent units (like players). As a coach I train a certain behavior in them, then let them play. So I'll be using an Object-Oriented Approach to this. -bash-3.2$ cat main #!/usr/bin/python print "Content-type: text/html\n\nHowdy" -bash-3.2$ ls -ld main -rwx------ 1 dgerman faculty 60 Apr 21 13:51 main -bash-3.2$ ------------------------------------------------------------------ -bash-3.2$ ls -ld * -rwx------ 1 dgerman faculty 111 Apr 21 13:58 main -rw-r--r-- 1 dgerman faculty 247 Apr 21 13:56 Parser.py -rw-r--r-- 1 dgerman faculty 478 Apr 21 13:58 Parser.pyc -bash-3.2$ cat main #!/usr/bin/python import Parser message = Parser.data["message"] print """ Message is: %s """ % (message) -bash-3.2$ cat Parser.py import cgi print "Content-type: text/html\n\n" input = cgi.FieldStorage() data = {} for name in ("message", "n1", "n2", "correct", "total", "answer"): if input.has_key(name): data[name] = input[name].value else: data[name] = "" -bash-3.2$ ----------------------------------------------------------- -bash-3.2$ more Parser.py main :::::::::::::: Parser.py :::::::::::::: import cgi print "Content-type: text/html\n\n" input = cgi.FieldStorage() data = {} for name in ("source", "n1", "n2", "correct", "total", "answer"): if input.has_key(name): data[name] = input[name].value else: data[name] = "" :::::::::::::: main :::::::::::::: #!/usr/bin/python import Parser class One(object): def show(self): print """
""" class Two(object): pass source = Parser.data["source"] if source in ("One", "Two", "Three", "Four"): pass else: screen = One() screen.show() -bash-3.2$ --------------------------------------------------------- -bash-3.2$ more Parser.py main :::::::::::::: Parser.py :::::::::::::: import cgi print "Content-type: text/html\n\n" input = cgi.FieldStorage() data = {} for name in ("source", "n1", "n2", "correct", "total", "answer"): if input.has_key(name): data[name] = input[name].value else: data[name] = "" :::::::::::::: main :::::::::::::: #!/usr/bin/python import Parser class One(object): def show(self): print """ """ def finalize(self): screen = Two() screen.show() class Two(object): def show(self): print """ """ def finalize(self): screen = Three() screen.show() class Three(object): def show(self): print """ """ source = Parser.data["source"] if source in ("One", "Two", "Three", "Four"): screen = eval(source + "()") screen.finalize() else: screen = One() screen.show() ------------------------------------------------------------