How to transfer data on SQL Table to Excel file in Python?
Question: So I have a working piece of code which creates and modifies data in a SQL
table. I now want to transfer all the data in the SQL table to a Excel file.
Which libraries would I use and what functions in those libraries would I use?


Answer: an example of database with sqlite: memory.db and table name is called table1
in the example

    
    
    import os
    import csv
    import sqlite3
    
    def db2csv(file,Table1):
        con = sqlite3.connect("memory.db")
        cur = con.cursor()
    
        if not os.path.exists(file):
            os.makedirs(file)
    
        with open(file, 'w', newline='') as csvfile:
            spamwriter = csv.writer(csvfile, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL)
            for row in cur.execute('SELECT * FROM Table1 '):
                spamwriter.writerow(row)
        con.commit()
    

