Home > front end >  Can't seem to call the pre_process function, comes up with undefined name. I know im being stup
Can't seem to call the pre_process function, comes up with undefined name. I know im being stup

Time:03-28

    def removeStopWords(words):
        return list(set([w for w in words if not w in sw.words('english')]))

    def pre_process(x_user):
        words = []
        with open("words.txt",'r') as data_file:
            textdata = data_file.readlines()
        for line in textdata:    
            try:
                words.append(line.split()[0].lower())
            except:
                pass    
            completed_words = removeStopWords(words)
            print(completed_words)
             
       
    def GButton_6_command(self):

        x_user = root.entry.get()
        pr = pre_process
        pr.user_words(x_user)
        model = pkl.load(open('Training_model.pkl', 'rb'))
        pred = model.predict(pr.user_words)
        print(pred)

Code is meant to take user input and apply ML program to user input. This is the gui, which works but when i try to call the pre_process, it classifies it as undefined name and i'm just trying to figure out why, im not great at coding XD

CodePudding user response:

I have noticed mistake at pr = pre_process, You have just stored the refrence to the function, to call the function you have to add opening and closing parenthesis after the function name, which in your case should be pr = pre_process().

I think you are using classes, so you can use self.pre_process()

Also i dont recommed you to take function variable value like this pr.user_words(x_user), I would suggest you to use return statement in your function to return the value to the variable from which you have called the function.

  • Related