0
votes

I need some help with my code, because I cannot understand why is giving to me this error (sqlite3.OperationalError: near ".": syntax error).

I want to export a database.db to database.csv from Python, and this code works fine on sqlite3, but when I typed on Python3 with cur.execute() this error appears.

Now this is my code where the bug is

fname = input('Name for the csv?\n> ')
cur.execute('.headers on')
cur.execute('.mode csv')
cur.execute(f'.output {fname}.csv')

I searched on other forums but I think that this is a particular case. I hope somebody can help me fixing the error, or giving me an alternative way to export the database to csv with python.

1

1 Answers

0
votes

You can't do that. These commands work only within the sqlite executable and can't be used like regular SQL commands or pragrmas. What you could do in Python is run a shell command.