Jack
Jack

Reputation: 49

Python error 'ascii' codec can't decode byte 0x90 in position 11: ordinal not in range(128)"

I do computing at school but their version of python is different to the one I have at home and every time I try to run a file I did at school on my home computer it says "

UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 11: ordinal not in range(128)"

Any help is appreciated

Here is my code so far.

classc = int(input("WHich classes scores do you want to see 1 or 2 or 3"))
if classc ==1:
    import csv


    print("H")
    with open("class1.csv","r") as csv1file:
        csvfile1reader = csv.reader(csv1file)
        csv1 = []
        for row in csvfile1reader:
            if len (row) != 0:
                csv1 = csv1 + [row]



        print("Here are the scores for class1 in aphabetical order!")
    import operator

    hl = open ("class1.csv","r")

    csvo = csv.reader(hl,delimiter='0')

    sort1 = sorted(csv1,key=operator.itemgetter(0))
    for row in sort1:
        print (row)
    print("these are the highest to lowest score")    
h2 = open ("class1.csv","r")
csvo = csv.reader(hl,delimiter=' ')
sort2 = sorted(csv1,key=operator.itemgetter(1))

for row in sort2:
        print (row)
import csv

with open('class1.csv') as handle:
    reader = csv.reader(handle)
    next(reader, None)
    for row in reader:
        user, *scores = row
        average = sum([int(score) for score in scores]) / len(scores)
        print (
            "{user} has average of {average}".format(user=user, average=average)
        )

Upvotes: 3

Views: 18824

Answers (1)

Derek T. Jones
Derek T. Jones

Reputation: 1822

0x90 is indeed out of range for ASCII, which only covers 0x00 to 0x7f. The file may be in some Unicode encoding, or it may be in some 8-bit encoding, in the ISO-8859 family. Once you have found that out, open your file with the codecs module. Supposing your encoding is ISO-8859-1:

with codecs.open('class1.csv', encoding='iso-8859-1') as handle:
    reader = csv.reader(handle)

Upvotes: 10

Related Questions