-2

so I am trying to get a random word for a project and I never used read in my code speaking of here's my code

import json
import random

Dictonaryftg = json.load("EnglishDictionary.json")

Words = list(Dictonaryftg.keys())

Rword = str(random.choice(Words))

print(Rword)

im pretty sure my issue resides here:

random.choice(Words)

But i can't find the issue

1 Answers1

0

The code should be

import json
import random

with open("EnglishDictionary.json", 'r') as f:
    Dictonaryftg = json.load(f)

The issue is that, json.load expects a file object, where you just passed the file name i.e. a string object.

Zero
  • 1,807
  • 1
  • 6
  • 17