IT 117: Intermediate Scripting
Quiz 8 Answers

  1. What does Python call the process by which an object can be stored as a file on disk?
    pickling
  2. If you want to turn an object into a file on disk, what statement must you have at the top of the script file?
    import pickle
  3. What access mode would you use to open a pickled file for reading?
    rb
  4. Write a Python statement that opens the pickle file students.pk for reading and assigns the result to the variable pickle_file.
    pickle_file = open('students.pk', 'rb')
  5. Write the name of the method you would use to read data from a pickle file.
    pickle.load
  6. What access mode would you use to open a pickled file for writing?
    wb
  7. Write a Python statement that opens the pickle file students.pk for writing and assigns the result to the variable pickle_file.
    pickle_file = open('students.pk', 'wb')
  8. Write the name of the method you would use to write data to a pickle file.
    pickle.dump
  9. If you have an import statement in a file defining the class, where must that statement appear?
    before the class declaration
  10. Using data hiding, write the constructor for the Car class with the attributes
    manufacturer
    model
    year
    color
    def __init__(self, manufacturer, model, year, color):
              self.__manufacturer = manufacturer
              self.__model        = model
              self.__year         = year
              self.__color	      = color