Sorting a list alphabetically from a CSV in Python by column
Question: I've written a piece of code that sends data to a .csv file, sorting by name,
and then 3 scores from a quiz. I need to call that data from the .csv file
created and sort the data alphabetically by name, numerically, and by average.
However, when I try to sort the names alphabetically, nothing comes up. I'm
quite new to Python so I can't see where my error is.

This is the part of my code that saves and (tries) to print the data.

    
    
    if class_number == 2:
        f = open("Class 2" + ".csv", 'a')
        writer = csv.writer(f, delimiter =',')
        writer.writerow([name, count1, count2, count3])
        print ("Your scores were", count1, ",", count2, ", and", count3)
    
        print("Would you like to see previous results?")
        print("Press 1 to see previous results for your class. Press 2 to close the program")
        answer = int(input())
        if answer == 1:
            print("How would you like data to be sorted?")
            print("Press 1 for alphabetically")
            print("Press 2 for highest to lowest")
            print("Press 3 for average")
            score = input()
            if score == 1:
                sample = open("Class 2.csv", "r")
                csv1 = csv.reader(sample, delimiter=",")
                sort = sorted(csv1, key=operator.itemgetter(0))
                for eachline in sort:
                    print("Class 2.csv", "r")
    

I'm really confused about what I'm doing wrong.

EDIT: The part of code I need help with is

    
    
    if score == 1:
                sample = open("Class 2.csv", "r")
                csv1 = csv.reader(sample, delimiter=",")
                sort = sorted(csv1, key=operator.itemgetter(0))
                for eachline in sort:
                    print("Class 2.csv", "r")
    

This part will not display for some reason, but without the "If score" part it
will display.


Answer: I've tested this with a csv file with one column and it worked. I'm assuming
you only want to display your result

    
    
    import csv
    import operator
    
    sample = open("file.csv", "r")
    csv_file = csv.reader(sample, delimiter=",")
    sort = sorted(csv_file)
    for eachline in sort:
        print eachline
    

