import sqlite3 conn = sqlite3.connect('my DB.db') c = conn.cursor() def insert_list_in_db(): # function used to insert my conctact_list in my DB for t in contact_list: #each element of t should be inserted in the rigth coloumn c.execute('insert into carnet_dadresses values (?,?,?,?,?)',t) contact_list =[] class Contact: nb_contact = 0 def __init__(self , nom, prenom='' , email ='', tel='' , whatsapp = '' ): self.nom=nom self.prenom= prenom self.email=email self.tel = tel self.whatsapp= whatsapp Contact.nb_contact +=1 self.nb=Contact.nb_contact self=[self.nom,self.prenom,self.email,self.tel,self.whatsapp] def show(self): ch = str(self.nb) print("Contact :" +ch +"\n Nom : "+self.nom +"\n Prenom : "+self.prenom +"\n Email : "+self.email +"\n Tel : "+self.tel +"\n Whatsapp : "+self.whatsapp) def Add(self): contact_list.append(self) def Supprimer(self): contact_list.remove(self) def my_contacts(self): print("List of my contacts :") for i in contact_list: Contact.show(i) def edit_contact(self): self.nom=input("Entre le nouveau nom :") self.prenom = input("Entre le nouveau prenom :") self.email = input("Entre le nouveau mail :") self.whatsapp = input("Entre le nouveau whatsapp :") self.tel = input("Entre le nouveau tel :") def enter_contact(self): nom = self.nom prenom = self.prenom email = self.email tel = self.tel whatsapp = self.whatsapp c.execute("INSERT INTO carnet_dadresses (nom, prenom, email, tel, whatsapp) VALUES (?, ?, ?, ?,?)", (nom, prenom, email, tel, whatsapp)) conn.commit() def create_table(): c.execute("CREATE TABLE IF NOT EXISTS carnet_dadresses(nom, prenom, email, tel, whatsapp)") conn.commit() C=Contact('eric','jean','sid@h.c','0011','144') C1=Contact('erric','michel','sid@h.c','1111','1111') create_table() insert_list_in_db() c.close conn.close()