Finish Python First Pass




CS256

Chris Pollett

Sep 18, 2017

Outline

Strings

Lists

Example Using Lists and Command Line

import sys
if(len(sys.argv)) != 2: 
   #notice sys.argv is a list of command-line args and we found its length
   print "Please supply a filename"
   raise SystemExit(1) # throw an error and exit
f = open(sys.argv[1]) #program name is argv[0]
lines = f.readlines() # reads all lines into list one go
f.close()

#convert inputs to list of ints
ivalues = [int(line) for line in lines]

# print min and max
print "The min is ", min(ivalues)
print "The max is", max(ivalues)

Example Files in a Folder as a List

import glob
path = './*'
files = glob.glob(path) 
for name in files:
   print name

Tuples

Sets

Dictionaries

Iteration and Looping

Examples of things can iterate over with for

Quiz

Which of the following is true?

  1. The learning update rule used for the perceptron convergence theorem and our PAC learning of nested boolean functions was the same.
  2. The perceptron convergence theorem shows perceptrons can learn an arbitrary function.
  3. To get a list of command line arguments in Python, you can call the open.argv() function of the sys package.

Functions

Function Scoping, Functions as Variables

Objects and Classes

Inheritance, static methods, abstract classes.

Exceptions

Modules

Documentation Strings and Help