In Class: Week 7 Monday and Wednesday

Create a week07 subdirectory in your cs21/class directory:

      % cd 
      % cd cs21/class
      % pwd

      % mkdir week07        
Then, from within your week07 subdirectory copy over some python files from my public directory:
    % cd week07
    % pwd

    % cp ~newhall/public/cs21/week07/* .
    % ls

We are going to do some of the following together in class:
    strings and lists as objects, and the random library:

  1. On the class schedule for week6 is a link to information about using strings and lists as objects, and about using the random library. Read through this, and look at the sample code that you copied over from my week07 subdirectoy (,,

    In the python interpreter, you can get information about list and str class method functions by calling help(class_name):

      $ python
      >>>  help(str)
      >>>  help(list)
    And, if you import the random library, you can get information about it by calling help too:
      $ python
      >>>  import random
      >>>  help(random)
    File I/O:

  2. open in vim. We will look at this code together and try running it to see if we understand what it is doing.

    Rules for using a file:

    1. open a file (open returns a new file object associated with the open file). It takes the file name and the mode in which to open the file as parameters.
      		infile = open("foo.txt", "r")
    2. call method functions on the file object to read or write characters from a file.
      		line = infile.readline()
    3. close the file.
    You can run help(file) in the python interpreter to see the method functions associated with a file object.