python 'self' is not defined
Question: File "database.py", line 6, in class data: File "database.py", line 17, in
data self.dbcommit() NameError: name 'self' is not defined

    
    
    from sqlite3 import dbapi2 as sqlite
    class data:
       def __init__(self,dbname):
           self.con=sqlite.connect(dbname)
       def __del__(self):
           self.con.close()
       def dbcommit(self):
           self.con.commit()
       def createtable(self):
           self.con.execute('create table db(ind,w)')
           self.dbcommit()
    e=data('search.db')
    e.createtable()
    


Answer: It's an indentation issue. The `def`s after `__init__` need to be indented the
same amount for Python to consider them to be part of the class.

Try:

    
    
    from sqlite3 import dbapi2 as sqlite
    
    class data:
        def __init__(self,dbname):
            self.con=sqlite.connect(dbname)
        def __del__(self):
            self.con.close()
        def dbcommit(self):
            self.con.commit()
        def createtable(self):
            self.con.execute('create table db(ind,w)')
            self.dbcommit()
    
    e=data('search.db')
    e.createtable()
    

