SQLite Forum

how to open or create db in sqlite3
Login
I have code in python to create or open db, but it is throwing error. Any suggestions
Error:" 'tuple' object does not support item assignment" 

import sqlite3
import os


class sqlite1():

    
    def __init__(self, pa, na, rq):

        
        self.dbname = None
        self.name = None
        self.id1 = 0



        if rq == 'open':
          
            print(pa, na)
            self.hdl = (os.path.join(pa, na),'open')
            if not b'id1' in self.hdl or not b'ns' in self.hdl:
                print("open")

            try:
                self.id1 = int(self.hdl[b'id1'])
                self.name = self.hdl[b'ns']
            except:
                pass

        else:
           
            self.hdl = (os.path.join(pa, na),'c')
            self.id1 = 0
            print("File created")

            self.hdl[b'id1'] = str(self.id1)
            


    def db_connect(self):
       
        con = sqlite3.connect(self.na)
        return con

    def getID(self):
        return self.hdl[b'id1']
    def setID(self, id1):
        self.hdl[b'id1'] = id1



Testscript:

from sqlite123 import *
from sqlite123 import sqlite1

class Test1:
    def __init__(self, pa, na, rq):
        self.pa = pa
        self.na = na
        self.id1 = 0
        self.scm1 = sqlite1(pa, na, rq)
        


    def fileopen(self, pa, na, rq):
        self.scm1 = sqlite1(pa, na, rq)
        



if __name__ == '__main__':
   
    tst = Test1('', 'file.db', 'c')
    tst.fileopen('', 'file.db', 'open')
   
    con1 = sqlite1.db_connect(tst)
    #cur = con1.cursor()