Python: Sqlite3 query output to .csv file -


i execute query:

select datetime(date/1000,'unixepoch','localtime') date, address received, body body sms; 

and save it's output .csv file in specified directory. in ubuntu terminal far more easy manually give commands save output of above query file. not familiar python-sqlite3. know how execute query , save it's output custom directory in .csv file. please me out !

quick , dirty:

import sqlite  db = sqlite.connect('database_file') cursor = db.cursor()  cursor.execute("select ...") rows = cursor.fetchall()   # itereate rows , write csv  cursor.close() db.close() 

rows list matching records, can iterate , manipulate csv file.

if want make csv file, @ csv module. following page should going https://docs.python.org/2/library/csv.html

you can @ pandas module create file.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -