-1

I am having trouble getting my dictionary to work. I am new to Python and I made a class for all the functionality of the dictionary to be placed into. Afterwards I tried to call the class to test my code and I got error after error. The error was

Traceback (most recent call last):
  File "C:/Users/prest/OneDrive/Desktop/coding/Dictionary_Project/index.py", line 31, in <module>
    print(dictFunctioning.finding_def())
TypeError: finding_def() missing 1 required positional argument: 'self'

I have tried to make another variable, replace self, and use the variable globally to put it in and the error still appears.

import json
from difflib import get_close_matches

data = json.load(open("data.json"))

class dictFunctioning:

    def __init__(self):
        self.user_word = input("Enter Word: ").lower()
        self.match_word = get_close_matches(self.user_word, data.keys(), cutoff=0.8)
        self.choice = input('Yes or No?')

    def finding_def(self):
        if self.user_word in data:
            return data[self.user_word]
        elif len(self.match_word) > 0:
            return "Did you mean %s instead?" % self.match_word[0]
            rechecker(self.choice)
        else:
            return self.user_word + " is not a real word. Please check spelling."

    def rechecker(self):
        if self.choice == 'Yes':
            return self.finding_def(self.match_word[0])
        elif self.choice == 'No':
            return 'Sorry, can not find the word you are looking for.'
        else:
            return 'That was not a correct response. Please type Yes or No'
            rechecker(self.choice)

print(dictFunctioning.finding_def())`

the dictionary file I am using can be found here: https://github.com/prestonjohnson17/Dictionary

Also another issue, I do not know if it is a problem yet because I cannot get my code to work to check it, but my text editor (PyCharm) is telling my the function rechecker() is unreachable in the instances I called it in the program.

Thanks In Advance!

Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

0

You need to create an object to call it on.

d = dictFunctioning()
print(d.finding_def())
Barmar
  • 741,623
  • 53
  • 500
  • 612