#!/usr/bin/python """ HelloWorld.py - Dan Sneddon (dan@dansneddon.com) This brief script demonstrates the following: 1) Basic command-line parameters (and printing usage) 2) Instantiating a custom class (Felicitations) 3) Defining and calling methods 4) Executing a main() method Creative Commons Attribution-NonCommercial 3.0 Unported License""" import string, sys greeting = None addressee = None punctuation = None class Felicitations(object): def __init__(self): self.felicitations = [ ] def addon(self, word): self.felicitations.append(word) def printme(self): greeting = string.join(self.felicitations[0:], "") print greeting def prints(string): string.printme() def hello(i): string = 'hell' + i return string def caps(word): value = string.capitalize(word) return value def printusage(): print 'Usage: ' + sys.argv[0] + ' [Greeting] [Addressee] [Punctuation]' sys.exit(2) def main(): salut = Felicitations() if greeting != 'Hello': cap_greeting = caps(greeting) else: cap_greting = greeting salut.addon(cap_greeting) salut.addon(", ") cap_addressee = caps(addressee) lastpart = cap_addressee + punctuation salut.addon(lastpart) prints(salut) if __name__ == '__main__': if len(sys.argv) < 4: printusage() greeting = sys.argv[1] addressee = sys.argv[2] punctuation = sys.argv[3] main()