Le 24 Mar 2005 06:16:12 -0800, Ben a écrit : > > Below is a few sample lines. There is the name followed by the class > (not important) followed by 5 digits each of which can range 1-9 and > each detail a different ability, such as fitness, attacking ability > etc. Finally the preferred foot is stated. > > Freddie Ljungberg Player 02808right > Dennis Bergkamp Player 90705either > Thierry Henry Player 90906either > Ashley Cole Player 17705left filename = 'players' # to adapt players = {} # mapping of name to abilities fin = open(filename) for line in fin: firstname, lastname, type_, ability = line.split() players[(lastname, firstname)] = Ability(ability) fin.close()
where Ability can be e simple function which return processed the information in the last word(string) of each line, or a class which stores/manages such information class Ability(object): def __init__(self, ability): digits = ability[:5] self.details = map(int, list(digits)) # list of details self.preferred_foot = ability[5:] # and so on .... > > > Thanks for your help > > ben > -- http://mail.python.org/mailman/listinfo/python-list