Computational Modeling Fall 2005 For today, you should have: 1) created an account on the wiki (http://wb/cm/cm-wiki.cgi/) 2) signed up for the class mailing list (http://lists.olin.edu/mailman/listinfo/CompMod) 3) read a chunk of your book 4) done HomeworkOne Today's outline: 1) present reviews from last time 2) identify recurring examples and concepts, and think about creating pages for some of them. When we have roughly one page per person, each of you will be in charge of maintaining an example/concept page. 3) trade books 4) learn a little Python For next time you should: 1) do HomeworkTwo 2) get a Python book Python crash course ------------------- Goal: introduction for people who don't know Python, review for those who do. More Pythonic than Software Design. Python for Java programmers: 1) Python is dynamically-typed, so no need to declare variables x = 5 x = 'allen' x = Histogram() 2) Python uses indentation to indicate nesting, no squiggly-braces and no semi-colons. The first line of a compound statement is a header that ends with a colon: if x<0 or x>100: print 'Pirate falls!' def square(x): return x**2 3) lists and dictionaries are built-in types with special syntax t = [1, 2, 3] print t[1] d = {} d['allen'] = 17 4) Python's OO features are very similar to Java's class Histogram(dict): def __init__(self, t): for x in t: self.count(x) def count(self, x): try: self[x] += 1 except KeyError: self[x] = 1 __init__ is a special name for the constructor, so when you invoke Histogram(), Python creates a new object and invokes __init__ on it exception handling! 5) Lots of online documentation at python.org