jslate1980 Posted February 13, 2015 Posted February 13, 2015 I am wanting to read information from a text file using Python. The format of the text file is Name Score with each result been on a newline by using “\n” for example: Karl 5 Dave 10 Steve 15 ETC I want to add this information into two lists one with the name and one with the numerical score. Any ideas?
pcstru Posted February 13, 2015 Posted February 13, 2015 https://docs.python.org/2/tutorial/inputoutput.html You open files with f = open('workfile', 'r') You can then loop through the file, line by line with something like : for line in f: For each line you want the elements out based on the space as a sep so array=line.split(' ') You should then have the elements as array[0] and array[1] and can append them to your separated lists. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now