Execute sqlite3 “dot” commands from Python or register collation in command line utility

前端 未结 6 1146
轮回少年
轮回少年 2021-02-07 01:34

My sqlite3 database contains a \"collate\" column-constraint. I\'ve placed it in the schema for the table, to prevent accidentally neglecting to use the necessary collation. How

6条回答
  •  长情又很酷
    2021-02-07 01:57

    You can call dot commands from Python using the subprocess module, which basically invokes a shell. If you need to use multiple dot commands, you can pass them as separate shell arguments - using a semicolon to separate them won't work.

    import subprocess
    subprocess.call(["sqlite3", "xxx.db", 
      ".mode tabs", 
      ".import file.tsv table_name"])
    

提交回复
热议问题