Write a class to create a binary file for storing the information of a student in the form of a dictionary and displays the content of the file created.


In [ ]:
import pickle
class student(object):
    '''Class to store information of a student and save it in a binary (pickled) file in the form of a dictionary.
        Attributes: 
            - info (dictionary)
            - filename (string)
        Methods:
            -enterData()
            -saveFile(filename)
            -displayFile()
    '''
    def __init__(self):
        self.info = {}
        self.filename = ''
    def enterData(self):
        self.info['name'] = raw_input('Enter Name: ')
        self.info['rollno'] = int(raw_input('Enter Roll No: '))
        self.info['admno'] = int(raw_input('Enter Admission No: '))
        self.info['class'] = int(raw_input('Enter class: '))
        self.info['grades'] = raw_input('Enter grades separated by space').split()
        self.filename = raw_input('Enter filename: ')
    def saveFile(self,filename = self.filename):
        f = open(filename,'wb')
        pickle.dump(self.info,f)
        f.close()
    def displayDile(self,filename = self.filename):
        f = open(filename,'rb')
        d = pickle.load(f)
        for i in d.keys():
            print i,d[i]
        f.close()