Pattern matching from a text document

Ben benji_tranter at hotmail.com
Wed Mar 23 11:40:05 EST 2005


I'm currently trying to develop a demonstrator in python for an
ontology of a football team. At present all the fit players are
exported to a text document.

The program reads the document in and splits each line into a string
(since each fit player and their attributes is entered line by line in
the text document) using list = target.splitlines()

The program then performs a loop like so:

while foo > 0:
    if len(list) == 0:
        break
    else:
        pat =
"([a-z]+)(\s+)([a-z]+)(\s+)([a-z]+)(\s+)(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})([a-z]+)"
        ph = re.compile(pat,re.IGNORECASE)

        match = ph.match(list[1])

        forename = match.group(1)
        surname = match.group(3)
        attacking = match.group(7)
        defending = match.group(8)
        fitness = match.group(9)

        print forename
        print len(list)
        del list[0]

The two main problems I'm having are that the first and entry in the
list is not printing. Once I have overcome this problem I then need
each player and there related variables to be stored seperately. This
is not happening at present because each time the loop runs it
overwrites the value in each variable.

Any help would be greatly appreciated.

Ben.




More information about the Python-list mailing list