1

I want to strip the scores from the file and arrange them in an ordered list where I can print out the 1st, 2nd and 3rd place, here is my code:

scores = []
result_f = open("results.txt")
for line in result_f:
    (name, score) = line.split()
    scores.append = (float(score))
result_f.close()
print("The highest scores were: ")
print(score[0])
print(score[1])
print(score[2])

the console error python gives is:

File "C:\Python34\surfingscores.py", line 5, in scores.append = (float(score)) AttributeError: 'list' object attribute 'append' is read-only

0

3 Answers 3

2

scores.append is a function. Instead of using

scores.append = float(score)

try using

scores.append = float(score)

or an alternatively

scores[len(scores):] = float(score)
Sign up to request clarification or add additional context in comments.

Comments

1

scores.append is a function/method of scores.

You need to make a function call.

scores.append(float(score))

Comments

1

You need

scores.append(float(score))

Currently you are trying to assign a float value to the attribute append of the scores list, which is not what you want. The error is thrown because the append attribute of your scores list (which is the function for appending to that list) is read-only and thus explicitly protected from what your current code is doing.

>>> scores = []
>>> scores.append
<built-in method append of list object at 0x7f08964f9638>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.