sumit
5/21/2019 - 8:11 AM

Read and Write variables using pickle

def readpickle(filename='gradesdict.p'):
  import pickle              # import module first
  f = open(filename, 'rb')   # 'r'/ 'rb' for reading; can be omitted
  variable = pickle.load(f)         # load file content
  f.close()                       
  return variable
  
def writepickle(variable, filename='gradesdict.p'):
  import pickle              # import module first
  # f = open('gradesdict.p', 'w')   # 'w'/'wb' Pickle file is newly created where foo1.py is
  f = open(filename, 'wb') 
  pickle.dump(variable, f)          # dump data to f
  f.close()  
  return