Right I've come across another problem in my coursework and cant seem to find anything similar in my lecture notes.
The aim of the definition is to delete a string (i.e. an entire player) from a list (i.e. my list of members) based upon search criteria, such as the players name.
So far i've only ever deleted single elements from a list not whole strings.
Here's what i've got so far... My code for deleting a player is under the function definition "delete_player. ..".
When I run my test code, my error states... ' "Member" object does not support indexing'. My main problems that if a player were to have the same surname then both would be deleted, so my only way round this is to have a unique i.d. for each player... Unless there's a way to have two search criteria's for deleting a player, i.e. forename and surname.
Example data from players.txt is...
A;Ed;Young;e.yo ung@lboro.ac.uk ;223376;1;0;1;0
B;Gordon;McTagg art-Cowan;g.b.mctag gart@lboro.ac.u k;226276;1;0;1; 0
C;Tom;Kane;t.g. kane@lboro.ac.u k;726653;1;0;1; 0
D;Chris;Holmes; c.r.holmes@lbor o.ac.uk;225378; 1;0;1;0
E;David;Mulvane y;d.k.mulvaney@ lboro.ac.uk;227 142;1;0;1;0
F;James;Buller; j.buller@lboro. ac.uk;223543;1; 0;1;0
I hope your able to understand what I'm trying to get at and can shed some ideas on how I'd be able to do this.
The aim of the definition is to delete a string (i.e. an entire player) from a list (i.e. my list of members) based upon search criteria, such as the players name.
So far i've only ever deleted single elements from a list not whole strings.
Here's what i've got so far... My code for deleting a player is under the function definition "delete_player. ..".
Code:
class Member(object):
'''a member in a squash team'''
players = open ("players.txt","r")
l= []
for line in players:
line=line.strip()
x = line.split(";")
memb = Member()
memb.id= x[0]
memb.forename= x[1]
memb.surname= x[2]
memb.email= x[3]
memb.phone= x[4]
memb.divc= x[5]
memb.pointc= x[6]
memb.divp= x[7]
memb.pointp= x[8]
l.append(memb)
players. close ()
def new_player(member_id,forename,surname,email,phone_number,division_current,points_current,division_previous,points_previous):
"""
Adds a new member to the register.
member_id = a number representing the
forename = a players forename
surname = a players surname
email = a players email
phone_number = a players phone number
division_current = the current division the player is in
points_current = the current points the player has
division_previous = the previous division the player was in
points_previous = the amount of points the player attained in the last round
"""
l.append([member_id,forename,surname,email,phone_number,division_current,points_current,division_previous,points_previous])
def delete_player(forename):
"""
Delete a member from the list
forename = a players forename (str)
"""
for j in range(0,len(l)):
x = l[j]
if x[1] == forename:
del l[j]
break
Example data from players.txt is...
A;Ed;Young;e.yo ung@lboro.ac.uk ;223376;1;0;1;0
B;Gordon;McTagg art-Cowan;g.b.mctag gart@lboro.ac.u k;226276;1;0;1; 0
C;Tom;Kane;t.g. kane@lboro.ac.u k;726653;1;0;1; 0
D;Chris;Holmes; c.r.holmes@lbor o.ac.uk;225378; 1;0;1;0
E;David;Mulvane y;d.k.mulvaney@ lboro.ac.uk;227 142;1;0;1;0
F;James;Buller; j.buller@lboro. ac.uk;223543;1; 0;1;0
I hope your able to understand what I'm trying to get at and can shed some ideas on how I'd be able to do this.
Comment