Sorting and aligning the contents of a text file in Python

Posted by Emily Price on Stack Overflow See other posts from Stack Overflow or by Emily Price
Published on 2010-03-27T10:06:15Z Indexed on 2010/03/27 11:33 UTC
Read the original article Hit count: 219

Filed under:

In my program I have a text file that I read from and write to. However, I would like to display the contents of the text file in an aligned and sorted manner. The contents currently read:

name, score
name, score

This is my code where the text file in read and printed:

elif userCommand == 'V':
    print "High Scores:"
    scoresFile = open("scores1.txt", 'r')
    scores = scoresFile.read().split("\n")
    for score in scores:
        print score
    scoresFile.close()

Would I have to convert this information into lists in order to be able to do this? If so, how do I go about doing this?

Thank you

© Stack Overflow or respective owner

Related posts about python