$ python myprogram.py http://www.calvin.edu/~stob/data/al0106.csv ... lots of output ....
Let’s do something fun!
How about parsing some stats? See http://www.calvin.edu/~stob/data/al0106.csv for Team stats for AL Teams for years 2001-2006
Can we write enough Python to answer some questions about the data?
Write a program that downloads a url and prints its contents.
Sample run
$ python myprogram.py http://www.calvin.edu/~stob/data/al0106.csv ... lots of output ....
Sample code for accessing the command line:
import sys
url = sys.argv[-1]
print url
Read a file url from the command line and:
break your file contents apart into a list of strings
print the number of lines in the list
print the list
Let’s explore list and str a little more thoroughly
Everything about lists: indexes and slices, methods, and mutability.
A lot like lists (indexing/slicing, looping)
But different too. split/join and "stringy" methods.
Immutability!
Make a list of just the home runs hit. Print it out.
Extra credit: print the total number of homeruns. See sum - but watch out for strings! Sample output:
$ python myprogram.py http://www.calvin.edu/~stob/data/al0106.csv
169
212
...
====
xxxx (Total)
Make a dictionary with team’s home run totals. Print it out.
BONUS: print out the team with the highest home run total.
$ python myprogram.py http://www.calvin.edu/~stob/data/al0106.csv
{'DET': 988, 'NYY': 1337,
... snip ...}
/
#