Dec-16-2017, 12:31 AM
So I came up with this following code, please bear with me if it is terrible. But its not giving me any syntax errors and seems to be running. When I re-open the text file to view the newly sorted results, the text file is empty. Is this because I am "w" and not "a"?
import itertools def main(): inputFile= open("students.txt", 'r') lineList = inputFile.readlines() with open("students.txt", "r") as text_file: for line in itertools.islice(text_file,0,2): my_tuple = (line) for n in my_tuple: sorted(my_tuple) inputFile.close() with open("students.txt", "w") as text_file: text_file.write(my_tuple) close.inputFile() main()