sqlite3.OperationalError: near ".": syntax error

Peter Otten __peter__ at web.de
Fri Sep 19 10:52:34 CEST 2014


luofeiyu wrote:

>      C:\Users\pengsir>d:\\sqlite3 F:\\workspace\\china\\data\\china.sqlite
>      SQLite version 3.8.5 2014-06-04 14:06:34
>      Enter ".help" for usage hints.
>      sqlite> .tables
>      balance   cash      fi_di     ipo       profile   quote
>      capital   dividend  fund      majority  profit
>      sqlite>
> 
>      import slqite3
>      con = sqlite3.connect('F:\\workspace\\china\\data\\china.sqlite')
>      cur = con.cursor()
>      cur.execute('.tables')
> 
> 
>      Traceback (most recent call last):
>        File "<stdin>", line 1, in <module>
>      sqlite3.OperationalError: near ".": syntax error
> 
> 
> why " cur.execute('.tables')  "  can't  get output?

.tables is a feature of the sqlite console, not part of sqlite's sql. Use

cur.execute("select name from sqlite_master where type = 'table';")

to emulate the command in python.




More information about the Python-list mailing list