why do I only end up with one object in the list
i want to keep appending

I am sure the answer is simple, thanks

studRoll = [] 

def GetInteger(i):
    try:
        return int(i)
    except:
        return 0

class stud:
    def __init__(self, a, n, m):
        self.age = a
        self.name = n
        self.mark = m

def ShowRoll():
    for stud in studRoll:print "\n\n\n>>>> Student Roll List <<<";print (stud.age,"-",stud.name,"-",stud.mark)

def AppendStudent(age,name,mark):
    global studRoll
    a = int(age)
    n = "" + name
    m = int(mark)
    s = stud(a,n,m)
    print "B4"
    ShowRoll()
    studRoll.append(s)
    s = None
    print "after"
    ShowRoll()

def AppendStudentObject(s):
    global studRoll
    studRoll.append(s)


print "****************** START OF RUN *******************"          

ShowRoll()

AppendStudent (1,"A",2)
AppendStudent (2,"b",4)
AppendStudent (3,"c",6)

studage=50
studname="kathleen"
studmark=90
AppendStudent (studage,studname,studmark)

s1=stud(4,"44",4)
s2=stud(5,"55",5)
s3=stud(6,"66",6)

AppendStudentObject(s1)
AppendStudentObject(s2)
AppendStudentObject(s3)

ShowRoll()

Editor's note:
Please use the [code] and [/code] tag pair to enclose your code.

Edited 3 Years Ago by happygeek: fixed formatting

The answer is really simple indeed. You do append. You just print your roll incorrectly. Hint: why do you print the header inside the loop?

Works fine for me as well. I get 7 entries at the end.

studRoll = []

def GetInteger(i):
   try:
      return int(i)
   except:
      return 0

class stud:
   def __init__(self, a, n, m):
      self.age = a
      self.name = n
      self.mark = m

def ShowRoll():
   for stud in studRoll:
      print "\n\n\n>>>> Student Roll List <<<"
      print (stud.age,"-",stud.name,"-",stud.mark)

def AppendStudent(age,name,mark):
   global studRoll
   a = int(age)
   n = "" + name
   m = int(mark)
   s = stud(a,n,m)
   print "---------------B4", a, n, m
   ShowRoll()
   studRoll.append(s)
##   s = None
   print "after" + "/" *30
   ShowRoll()

def AppendStudentObject(s):
   global studRoll
   studRoll.append(s)


print "****************** START OF RUN *******************"

ShowRoll()

AppendStudent (1,"A",2)
AppendStudent (2,"b",4)
AppendStudent (3,"c",6)

studage=50
studname="kathleen"
studmark=90
AppendStudent (studage,studname,studmark)

s1=stud(4,"44",4)
s2=stud(5,"55",5)
s3=stud(6,"66",6)

AppendStudentObject(s1)
AppendStudentObject(s2)
AppendStudentObject(s3)

ShowRoll()

print "="*60
print "length =", len(studRoll)
This article has been dead for over six months. Start a new discussion instead.