Create four band members from the class BandMember. Pickle these objects and store them in a file. Unpickle, then output the objects.
What will be an ideal response?
```
# Pickles and stores four BandMember objects.
import sys, cPickle, BandMember
try:
file = open( "band.dat", "w" ) # open file for writing
except IOError:
print >> sys.stderr, "File could not be opened."
sys.exit( 1 )
# create list of BandMember objects
musicians = [ BandMember.BandMember( "Bob", "guitar" ),
BandMember.BandMember( "Mary", "bass guitar" ),
BandMember.BandMember( "Casey", "guitar" ),
BandMember.BandMember( "Mike", "drums" ) ]
# pickle and store list of BandMember objects
cPickle.dump( musicians, file )
file.close()
```
```
# Unpickles and prints four band members.
import sys, cPickle, BandMember
try:
file = open( "band.dat", "r" ) # opens file for reading
except IOError:
print >> sys.stderr, "File could not be opened."
sys.exit( 1 )
# retrieve objects from file
members = cPickle.load( file )
file.close()
for member in members:
print member
```
Bob plays the guitar
Mary plays the bass guitar
Casey plays the guitar
Mike plays the drums
You might also like to view...
If you use a byte to store the grayscale information of each pixel in a grayscale image, how many gray levels are possible for each pixel?
What will be an ideal response?
Give several reasons why it may not be useful to store logically contiguous pages from a process’s virtual memory space in physically contiguous areas on secondary storage.
What will be an ideal response?
The body of a namespace is delimited by ________.
Fill in the blank(s) with the appropriate word(s).
What symbol is used as the Not logical operator in C++?
A. B. x C. ! D. ?