-1

I'm trying to use a method from a class in one of my methods in another file but i am receiving an error

#File 2
class Database():
    def __init__(self,loggedIn):
        self.loggedIn = False

def login(self,username, password):
        conn=sqlite3.connect("system.db")
        cur=conn.cursor()
        find_user = ("SELECT * FROM customerDetails WHERE email = ? AND 
        password = ?")
        cur.execute(find_user, [(username), (password)])
        results = cur.fetchall()

#File 1
login = Database.login(username_text.get(),password2_text.get())

NameError: name 'Database' is not defined

Stec
  • 37
  • 5

1 Answers1

0

As one of the first lines in file1.py, do:

from file2 import Database

Otherwise, it has no notion of what Database is or where it comes from.

This is assuming your filenames are file1.py and file2.py.

brentertainer
  • 2,118
  • 1
  • 6
  • 15