title: How to unpickle objects from .pkl file using python
body: <p>I created a student class.I stored every student details in a file.I used serialization concept to store the details.The problem is while unpickling the data it gives first object only.Can anyone say how to retrieve all objects which are in .pkl file </p>
  
  <p>and my code is</p>
  
  <p>this is my code</p>
  
  <pre><code>'''
  Created on Apr 20, 2015
  
  @author: murali
  
  '''
  import pickle
  from pip._vendor.distlib.compat import raw_input
  class Student:
      def __init__(self, name, roll, sex, subject, total):
          """Return a new Car object."""
          self.name = name
          self.roll = roll
          self.sex = sex
          self.subject = subject
          self.total = total
  
  print ("*************MENU*******************************")
  print ("\t 1.Add New Student")
  print ("\t 2.Display all Students")
  print ("\t 3.Delete Student")
  print ("\t 4.Display all Boys")
  print ("\t 5.Display all Girls")
  print ("\t 6.Display ascending order of marks")
  print ("\t 7.Display alphabetical order of names ")
  print ("\t 0.exit")
  print ("************************************************")
  
  print ("\n Enter your choice")
  ch=int(raw_input())
  
  if ch==1:
      print ("Enter Student Details")     
      print ("Enter Student Name")  
      n=raw_input()
      print ("Enter Student Roll number") 
      r=raw_input()
      print ("Male or Female")
      s=raw_input()
      print ("Enter Subject ")
      su=raw_input()
      print ("Enter Student marks ")
      t=raw_input()
      s=Student(n,r,s,su,t);
      with open("save2.pkl",'ab') as outfile:
          pickle.dump(s,outfile)
          print ("Data saved Successfully")
  elif ch==2:
      st=[];
      f=open("save2.pkl",'rb')
      storedlist=pickle.load(f)
      print (storedlist)
      #st.append(storedlist)
      print ("Students are-")
      print (storedlist)
      #for i in storedlist:
      print(storedlist.name)
      print(storedlist.roll)
      print(storedlist.sex)
      print(storedlist.subject)
      print(storedlist.total)
      f.close();
      #s1=None
      #with open("save2.pkl",'rb') as infile:
          #s1=pickle.load(infile)
          #print (s1.name)
          #print (s1.roll)
          #print (s1.sex)
          #print (s1.subject)
  </code></pre>