Python Forum
NameError: name 'score' is not defined - Help?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError: name 'score' is not defined - Help?
#11
Question 
(Mar-05-2023, 09:17 PM)deanhystad Wrote: A json file is text, just like a CSV file is text. Both are just a special way to format text in a file. Probably a good idea to stick with a CSV format file as it looks more "texty".

BTW, this does nothing:
f.close
If you want to close the file it should be f.close(). However, you don't need to close the file because that is handled by your file open context manager (with open(r'leaderboard.txt', 'a') as f:).

You need to tell us what problem you are having, and you should post some code showing how you are trying to read the information from the file. So far, the only code you've posted is one that reads strings from the file. You need something that will read names and scores. Since it is a CSV format file I wonder if there are any Python tools for reading that kind of file?

Hmm... I'm not sure what you're getting at, sorry. We're using a .txt file.

I forgot to put the (). My apologies.

Also, I've been trying to show you the code for what we've done. And explained it (although badly I think?). Yeah, we do, but the only thing we're allowed to use (I believe) is
import random
import os.path
import json

random.seed()


We're only allowed to use those packages. I'm just not sure how we're going to do the loading and saving in the predefined list. That's the main reason why I asked here. I've showed you the code we're working with, and we're confused on how to get it to work. Wall

Any help would be appreciated again.

Thanks. And sorry if I sounded rude.
Reply


Messages In This Thread
RE: NameError: name 'score' is not defined - Help? - by MrKnd94 - Mar-06-2023, 12:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to update score value? Mavoz 5 5,333 Nov-08-2022, 12:37 AM
Last Post: Mavoz
  How to correct the NameError: name 'xx' is not defined? vokoyo 5 18,363 Feb-17-2021, 05:55 AM
Last Post: delonbest
  NameError: name 'os' is not defined, & load_files(sys.argv[1]) AryaIC 3 6,553 Nov-07-2020, 07:45 PM
Last Post: jefsummers
  Error in code NameError: name ' ' is not defined ppman00 11 12,875 Sep-18-2020, 05:22 AM
Last Post: ndc85430
  NameError: name 'print_string' is not defined jamie_01 2 2,901 Jun-11-2020, 05:27 AM
Last Post: buran
  "NameError: name 'catName1' is not defined tofif 3 7,289 Jun-24-2019, 06:05 AM
Last Post: perfringo
  NameError x not defined Bruizeh 5 9,944 Feb-27-2019, 10:59 AM
Last Post: Larz60+
  NameError: name 'mailbox_list' is not defined pythonnewb 2 5,667 Aug-06-2017, 09:31 PM
Last Post: pythonnewb
  Average score MartinEvtimov 5 8,694 Apr-02-2017, 07:35 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020