4. My Guidelines
❖ we will use python as a learning language (I will give you lots of
example code)
❖ I will survey existing tools for each topic (but I’ll introduce you to just
one or two)
❖ I will bring in people to give examples (because you need to build
something to get your degree)
❖ you will get out as much as you put in (I aim to help beginners,
intermediates, and experts)
❖ you will learn how to learn (because you won’t become a programer
overnight)
8. Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Readability counts.
–PEP 20 (The Zen of Python)
10. Modules & Packages
❖ any file is a “module”
❖ packages: “App Store” for re-usable code via pip or
easy_install
❖ logging, testing, etc.
❖ Make your own: folder-based hierarchy with the magic
__init__.py file
❖ https://wiki.python.org/moin/UsefulModules
❖ https://pypi.python.org/pypi
17. Programming Approaches
❖ Imperative
❖ Everything is global, doesn’t scale well
❖ Procedural
❖ Make procedures to separate things
❖ Object-Oriented
❖ Encapsulate complexity via abstraction
❖ Event-Driven
❖ Limit scope to reduce complexity
❖ Functional
❖ Functions operate on data so you don’t manage state
❖ demos
18. Homework
❖ setup python (v2.7)
❖ setup git (github.com has great instructions)
❖ clone this repo: https://github.com/rahulbot/Programming-Style-Examples
❖ push homework to a git repository (github or elsewhere)
❖ beginner:
❖ modify an example to count total votes counts for each person
❖ intermediate:
❖ create an election results module to encapsulate all the loading, add methods for accessing total vote
counts and other features
❖ advanced:
❖ build a module that scrapes (use BeautifulSoup) more detailed election data
❖ http://www.archives.gov/federal-register/electoral-college/2012/popular-vote.html
❖ add the ability to export it to CSV and JSON