0

I've looked for similar topics on stack overflow and google, but I couldn't find any similar case. Can anyone help me?

import os
import tempfile
import sqlite3
import pandas as pd

tmp = tempfile.mktemp()
try:
        tmpDb = sqlite3.connect(tmp)
finally:
        try:
            if os.path.exists(tmp):
                os.remove(tmp)
        finally:
            tmpDb.commit()
accessions= ["WP_010881498.1", "WP_010881746.1", "WP_010881771.1"]
accessions_df = pd.DataFrame(accessions, columns= ['accessions'])
accessions_df.to_sql(name = "query", con = tmpDb, if_exists = 'replace')
jarlh
  • 42,561
  • 8
  • 45
  • 63
vini8cs
  • 1
  • 1
  • You remove the file you have just to create, so yes there is an I/O Error because the file do not exist anymore :) Why do you create a temporary database? In this case, use `sqlite3.connect(':memory:')` to create a database in memory. – Corralien Mar 06 '22 at 20:50
  • It was my first time using a temporary file. Sorry for the stupid mistake and thank you very much for your help @Corralien!!!!! – vini8cs Mar 06 '22 at 21:04

0 Answers0